Tech Support > Microsoft Windows > Windows CRM > Retriving Entity XSD's with custom fields
Retriving Entity XSD's with custom fields
Posted by Chris Ericoli on September 9th, 2004


Hi,

I know this question has been answered in this group before, but I was not
smart enough to take note at the time.

I would like to know how it might be possible to retrieve an Entity XSD that
includes all of the custom fields that have been added to the entitiy. I
want to use this to create strongly typed data objects for record updating,
rather than hard coding bloody XML strings all the time.

If anyone knows what I mean, and can help me - that would be great!

Cheers

Chris


Posted by Mj Miller \(MSFT\) on September 9th, 2004


Here's the information I posted on how to do this. Note, this is unsupported
stuff, but it does work and it's not going to break anything

http://inside-mscrm.blogspot.com/200...roken-xsd.html

--
Mj Miller
Technical Lead
Microsoft CRM

This posting is provided "AS IS" with no warranties, and confers no rights.

"Chris Ericoli" <cericoliNOspm@removethisfamill.com.au> wrote in message
news:u1cF3gjlEHA.3612@TK2MSFTNGP12.phx.gbl...


Posted by Chris Ericoli on September 10th, 2004


Thanks - has worked a treat.

V. Cool.

Cheers

Chris

"Mj Miller (MSFT)" <mikemill@microsoft.com> wrote in message
news:%237hVlQrlEHA.3912@TK2MSFTNGP12.phx.gbl...


Posted by Chris Ericoli on September 13th, 2004


Hi MJ -

That code works brilliantly - just wondering whether you've done any work
serializing the query object. I tried recreating the schema, and using the
XSD tool, but had some very weird results.

Cheers

Chris


"Mj Miller (MSFT)" <mikemill@microsoft.com> wrote in message
news:%237hVlQrlEHA.3912@TK2MSFTNGP12.phx.gbl...


Posted by Mj Miller \(MSFT\) on September 13th, 2004


What do you mean "the query object"? Are you talking about <fetch> or about
the <savedquery> bits that wrap fetch? Are you using the VS.Net XSD tool or
Dan's XSDObjectGen to get classes?

--
Mj Miller
Technical Lead
Microsoft CRM

This posting is provided "AS IS" with no warranties, and confers no rights.

"Chris Ericoli" <cericoliNOspm@removethisfamill.com.au> wrote in message
news:uTUQpaTmEHA.2764@TK2MSFTNGP11.phx.gbl...


Posted by Chris Ericoli on September 14th, 2004


Mj -

I meant the fetch - but I worked out the problem, and it was in my
recreating the schema. - was using XSDObjectGen.

Cheers

Chris

"Mj Miller (MSFT)" <mikemill@microsoft.com> wrote in message
news:%23EUijQbmEHA.3060@TK2MSFTNGP14.phx.gbl...


Posted by Chris Ericoli on September 14th, 2004


Mj -

I do have another question re your code though. The bit on creating
collection objects was a bit lost on me. I added some lines to the sql
script that i thought would result in collection object:

insert @view (value) values (' <xsd:complexType name="' + @entityName +
'Collection">')
insert @view (value) values (' <xsd:sequence>')
insert @view (value) values (' <xsd:element name="' + @entityName + '"
type="tns:' + @entityName + '" minOccurs="0"
maxOccurs="unbounded"></xsd:element>')
insert @view (value) values (' </xsd:sequence>')
insert @view (value) values (' </xsd:complexType>')
insert @view (value) values (' ')

This results in xml as:

<xsd:complexType name="accountCollection">
<xsd:sequence>
<xsd:element name="account" type="tns:account" maxOccurs="unbounded"
minOccurs="0"></xsd:element>
</xsd:sequence>
</xsd:complexType>

Which I thought should result in collection objects, but instead i get the
following - which C# objects to because it double defines
accountCollection?:

[Serializable]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public class accountCollection : ArrayList
{
public account Add(account obj)
{
base.Add(obj);
return obj;
}

public account Add()
{
return Add(new account());
}

public void Insert(int index, account obj)
{
base.Insert(index, obj);
}

public void Remove(account obj)
{
base.Remove(obj);
}

new public account this[int index]
{
get { return (account) base[index]; }
set { base[index] = value; }
}
}



[XmlType(TypeName="accountCollection",Namespace=Dec larations.SchemaVersion),
XmlRoot,Serializable]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public class accountCollection
{
[System.Runtime.InteropServices.DispIdAttribute(-4)]
public IEnumerator GetEnumerator()
{
return accountCollection.GetEnumerator();
}

public account Add(account obj)
{
return accountCollection.Add(obj);
}

[XmlIgnore]
public account this[int index]
{
get { return (account) accountCollection[index]; }
}

[XmlIgnore]
public int Count
{
get { return accountCollection.Count; }
}

public void Clear()
{
accountCollection.Clear();
}

public account Remove(int index)
{
account obj = accountCollection[index];
accountCollection.Remove(obj);
return obj;
}

public void Remove(object obj)
{
accountCollection.Remove(obj);
}


[XmlElement(Type=typeof(account),ElementName="accou nt",IsNullable=false,Form
=XmlSchemaForm.Unqualified,Namespace=Declarations. SchemaVersion)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public accountCollection __accountCollection;

[XmlIgnore]
public accountCollection accountCollection
{
get
{
if (__accountCollection == null) __accountCollection = new
accountCollection();
return __accountCollection;
}
set {__accountCollection = value;}
}

public accountCollection()
{
}

public void MakeSchemaCompliant()
{
}
}

I know that you specifically mention that your code isn't supported - and
I know that I'm asking for help that your time probably doesn't permit you
to give easily, but I would really appreciate any assistance you might be
able to pass on.

Cheers

Chris





"Mj Miller (MSFT)" <mikemill@microsoft.com> wrote in message
news:%23EUijQbmEHA.3060@TK2MSFTNGP14.phx.gbl...


Posted by Mj Miller \(MSFT\) on September 14th, 2004


Yeah, that's a copy / edit / paste problem on my part. You want the SQL to
look something like this instead. Notice that I'm using the entity
collection name instead (make sure you add a variable for @collectionname
and that you grab it in the cursor fetch). So, for example, with Account
you'll get a class called 'account' and one called 'accounts'. 'accounts'
will be of type accountCollection. From there I've been able to use any of
the bulk retrieve operations (except <fetch> which returns XML in the wrong
flavor) and serialize that XML into a collection using the same serialize /
deserialize code.

if @generateCollections = 1 and @collectionname is not null
begin
insert @view (value) values ('')
insert @view (value) values (' <xsd:complexType name="' +
@collectionname + '" final="#all">')
insert @view (value) values (' <xsd:sequence>')
insert @view (value) values (' <xsd:element name="' +
@entityname + '" minOccurs="1" maxOccurs="unbounded" type="tns:' +
@entityname + '" />')
insert @view (value) values (' </xsd:sequence>')
insert @view (value) values (' </xsd:complexType>')
end


--
Mj Miller
Technical Lead
Microsoft CRM

This posting is provided "AS IS" with no warranties, and confers no rights.

"Chris Ericoli" <cericoliNOspm@removethisfamill.com.au> wrote in message
news:OEq3V$emEHA.3876@TK2MSFTNGP15.phx.gbl...


Posted by Chris Ericoli on September 15th, 2004


Thansk Mj -

I must say your code and contribution is fantastic. I'm looking forward to
some more articles on the official MSDN blog.

Cheers

Chris

"Mj Miller (MSFT)" <mikemill@microsoft.com> wrote in message
news:O4ISPxpmEHA.2500@TK2MSFTNGP09.phx.gbl...



Similar Posts