|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Reading database schema, identity fields are added automaticallyI have an XSD file that contains some tables and some relations. Let's focus on a table named "Role". This table has one primary key, named "RoleId", a foreign key named "ApplicationId" and 3 more normal fields, summing 5 fields in total. As a help for you, I show the corresponding XSD fragment : <xs:element name="Role" sql:relation="Role" sql:key-fields="RoleId"> <xs:complexType> <xs:sequence> <xs:element ref="MenuOptionByRole" minOccurs="0" maxOccurs="unbounded" /> <xs:element ref="RoleByUser" minOccurs="0" maxOccurs="unbounded" /> </xs:sequence> <xs:attribute name="RoleName" use="required" sql:relation="Role" sql:field="RoleName" sql:datatype="varchar"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:maxLength value="50" /> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="RoleId" type="xs:integer" use="required" sql:relation="Role" sql:field="RoleId" sql:datatype="int" sql:identity="ignore" /> <xs:attribute name="ApplicationId" sql:relation="Role" sql:field="ApplicationId" sql:datatype="int" type="xs:integer"> </xs:attribute> <xs:attribute name="Description" sql:relation="Role" sql:field="Description" sql:datatype="varchar"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:maxLength value="256" /> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="LastUpdatedDate" use="required" sql:relation="Role" sql:field="LastUpdatedDate" sql:datatype="datetime"> <xs:simpleType> <xs:restriction base="xs:dateTime"> <xs:pattern value="\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}T\p{Nd}{2}:\p{Nd}{2}:\p{Nd}{2}" /> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:complexType> <xs:key name="Role_PrimaryKey_0"> <xs:selector xpath="." /> <xs:field xpath="@RoleId" /> </xs:key> <xs:keyref name="Role_To_MenuOptionByRole_FK_MENUOPTI_REFERENCE_ROLE" refer="Role_PrimaryKey_0"> <xs:selector xpath="MenuOptionByRole" /> <xs:field xpath="@RoleId" /> </xs:keyref> <xs:keyref name="Role_To_RoleByUser_FK_ROLEBYUS_REFERENCE_ROLE" refer="Role_PrimaryKey_0"> <xs:selector xpath="RoleByUser" /> <xs:field xpath="@RoleId" /> </xs:keyref> </xs:element> Using VS2005 XSD designer, I see that "RoleId" is correctly marked as primary key. When I use DataSet.ReadXmlSchema, resulting DataSet contains a "Role" table that has 7 fields. The fields that are configured in XSD file and 2 more auto-generated fields: Role_Id and Application_Id. These new fields are used by DataRelation objects which are also created automatically with the problem that they don't contain valid data as I am using RoleId and ApplicationId. How can I avoid that automatic generation and force the DataSet to use my own keys? By examing Role table columns, I saw that Role_Id column is marked as autoincremented, however my own RoleId column isn't marked as autoincremented. I set RoleId as sql:identity="ignore" but this didn't work Any help would be greately appreciated, thanks Jaime I just wanted to tell you that I have solved this problem by myself. I needed
just to use VS2005 DataSet designer and not XML Designer as I was doing. By using DataSet designer I deleted all keys and relations added automatically by the system and the re-relate all the tables. That way all worked perfect. Thanks anyway Jaime Show quote "Jaime Stuardo" wrote: > Hi all... > > I have an XSD file that contains some tables and some relations. Let's focus > on a table named "Role". This table has one primary key, named "RoleId", a > foreign key named "ApplicationId" and 3 more normal fields, summing 5 fields > in total. As a help for you, I show the corresponding XSD fragment : > > <xs:element name="Role" sql:relation="Role" sql:key-fields="RoleId"> > <xs:complexType> > <xs:sequence> > <xs:element ref="MenuOptionByRole" minOccurs="0" > maxOccurs="unbounded" /> > <xs:element ref="RoleByUser" minOccurs="0" maxOccurs="unbounded" /> > </xs:sequence> > <xs:attribute name="RoleName" use="required" sql:relation="Role" > sql:field="RoleName" sql:datatype="varchar"> > <xs:simpleType> > <xs:restriction base="xs:string"> > <xs:maxLength value="50" /> > </xs:restriction> > </xs:simpleType> > </xs:attribute> > <xs:attribute name="RoleId" type="xs:integer" use="required" > sql:relation="Role" sql:field="RoleId" sql:datatype="int" > sql:identity="ignore" /> > <xs:attribute name="ApplicationId" sql:relation="Role" > sql:field="ApplicationId" sql:datatype="int" type="xs:integer"> > </xs:attribute> > <xs:attribute name="Description" sql:relation="Role" > sql:field="Description" sql:datatype="varchar"> > <xs:simpleType> > <xs:restriction base="xs:string"> > <xs:maxLength value="256" /> > </xs:restriction> > </xs:simpleType> > </xs:attribute> > <xs:attribute name="LastUpdatedDate" use="required" > sql:relation="Role" sql:field="LastUpdatedDate" sql:datatype="datetime"> > <xs:simpleType> > <xs:restriction base="xs:dateTime"> > <xs:pattern > value="\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}T\p{Nd}{2}:\p{Nd}{2}:\p{Nd}{2}" /> > </xs:restriction> > </xs:simpleType> > </xs:attribute> > </xs:complexType> > <xs:key name="Role_PrimaryKey_0"> > <xs:selector xpath="." /> > <xs:field xpath="@RoleId" /> > </xs:key> > <xs:keyref name="Role_To_MenuOptionByRole_FK_MENUOPTI_REFERENCE_ROLE" > refer="Role_PrimaryKey_0"> > <xs:selector xpath="MenuOptionByRole" /> > <xs:field xpath="@RoleId" /> > </xs:keyref> > <xs:keyref name="Role_To_RoleByUser_FK_ROLEBYUS_REFERENCE_ROLE" > refer="Role_PrimaryKey_0"> > <xs:selector xpath="RoleByUser" /> > <xs:field xpath="@RoleId" /> > </xs:keyref> > </xs:element> > > > Using VS2005 XSD designer, I see that "RoleId" is correctly marked as > primary key. > > When I use DataSet.ReadXmlSchema, resulting DataSet contains a "Role" table > that has 7 fields. The fields that are configured in XSD file and 2 more > auto-generated fields: Role_Id and Application_Id. These new fields are used > by DataRelation objects which are also created automatically with the problem > that they don't contain valid data as I am using RoleId and ApplicationId. > > How can I avoid that automatic generation and force the DataSet to use my > own keys? > > By examing Role table columns, I saw that Role_Id column is marked as > autoincremented, however my own RoleId column isn't marked as > autoincremented. I set RoleId as sql:identity="ignore" but this didn't work > > Any help would be greately appreciated, thanks > > Jaime > |
|||||||||||||||||||||||