الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

XSD Files and Database Schema

مغلق
بدأه Usama Fayez في 5 مايو 2006 · 3 رد · 762 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

أنا بشتغل في مشروع عبارة عن Add-in و محتاج أعرف إذا كاني يوجد طريقة أقدر بيها أعمل Generate لملف XSD إللي بيتخزن فيه معلومات عن ال Typed Dataset

المشكلة إني لما أجي أعمل Generate للملف XSD عن طريق Dataset.SaveXMLSchema بيخزن معلومات عن الجداول بس طبعا مبيخزنش أي معلومات عن الSQL Statements زي الSelect Statements إلخ ... فلما أجي أضيف ملف ال XSD للمشروع بيتعمل Typed Dataset و شوية Tables لكن مبيتعملش طبعا Table Adapters

يا ترى في حل للمشكلة دي ؟؟؟

طيب لو مفيش حل و المفروض بنفسي أكتب كل حاجة في ملف ال XSD عن ال SQL Statements يا ترى أعرف أقرا فين عن ال Format بتاع الملف ده علشان أقدر أفهم كل حاجة فيه و أضيف فيه البيانات إزاي ؟؟

شكرا

#2

الـ XSD أو الـ Schema تم الاتفاق عليها من أجل وصف البيانات فقط وليس من أجل حفظ البيانات , ومن الخطأ جدا أن تحفظ فيها أشياء أخرى غير تلك الأشياء التي تصف بها البيانات. اذا أردت حفظ جمل الـ Select والخ فاحفظها في ملف آخر لأنها أشياء لا تتعلق بوصف البيانات اطلاقا.

#Read

http://MoutazShams.blogspot.com

projects003.gif

أعتذر عن التغيب هذه الأيام نظرا للانشغال المريب

#3

السلام عليكم

يمكن أنا موضحتش قصدي كويس

ده مثال على ملف XSD معمول بفيجوال ستوديو

و فيجوال ستوديو بيستخدم الملف ده علشان يعمل Generate لل Code بتاع ال Table Adapters و ال Typed Dataset و ال Data Tables إلخ ...

دلوقتي الكود ده جزئين الجزء الأول فيه ال Connection و ال Commands يعني المعلومات اللازمة لتوليد كود ال Table Adapters

و ده فيه الSQL Statements الخاصة بالCommands

الجزء التاني فيه معلومات عن قاعدة البيانات زي الجدوال و العلاقات بينها إلخ ... و ده بيستخدم لتوليد الTyped Dataset و ال Data Tables

دلوقتي الجزء الثاني سهل توليده يعني أي DataAdapter تخليه يعمل Fill لل Schema في أي Dataset و تعمل SaveXMLSchema حيديك الجزء الثاني و ممكن تخزنه كملف XSD و لو جربت تضيفه لمشروع حتلاقي فيجوال ستوديو يولد كود ال Typed Dataset على طول بس طبعا من غير أي Table Adapters

و هي دي المشكلة

دلوقتي أنا عايز أجيب الجزء الأول الخاص بتوليد الTable Adapters فهل في طريقة مباشرة أولده بيها زي بتاعة SaveXMLSchema الخاصة بالثاني ؟

طيب لو مفيش طريقة مباشرة أقدر أقرا فين عن صيغة الجزء ده علشان مش فاهمها يعني مش حعرف أعمل كود يكتبها لإني مش فاهمها من الأساس أنا دورت في MSDN و ملقيتش حاجة حتى لو فهمت الجزء إللي موجود ده فده مش كافي إني أعرف أفهمها كويس لإن أكيد في حاجات تانية ممكن تقابلني بعدين

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="BooksDataSet" targetNamespace="http://tempuri.org/BooksDataSet1.xsd" xmlns:mstns="http://tempuri.org/BooksDataSet1.xsd" xmlns="http://tempuri.org/BooksDataSet1.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop" attributeFormDefault="qualified" elementFormDefault="qualified">
  <xs:annotation>
    <xs:appinfo source="urn:schemas-microsoft-com:xml-msdatasource">
      <DataSource DefaultConnectionIndex="0" FunctionsComponentName="QueriesTableAdapter" Modifier="AutoLayout, AnsiClass, Class, Public" SchemaSerializationMode="IncludeSchema" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
        <Connections>
          <Connection AppSettingsObjectName="Settings" AppSettingsPropertyName="BooksConnectionString" ConnectionStringObject="" IsAppSettingsProperty="True" Modifier="Assembly" Name="BooksConnectionString (Settings)" ParameterPrefix="@" PropertyReference="ApplicationSettings.tstDataSet.Properties.Settings.GlobalReference.Default.BooksConnectionString" Provider="System.Data.SqlClient">
          </Connection>
        </Connections>
        <Tables>
          <TableAdapter BaseClass="System.ComponentModel.Component" DataAccessorModifier="AutoLayout, AnsiClass, Class, Public" DataAccessorName="AuthorsTableAdapter" GeneratorDataComponentClassName="AuthorsTableAdapter" Name="Authors" UserDataComponentName="AuthorsTableAdapter">
            <MainSource>
              <DbSource ConnectionRef="BooksConnectionString (Settings)" DbObjectName="Books.dbo.Authors" DbObjectType="Table" FillMethodModifier="Public" FillMethodName="Fill" GenerateMethods="Both" GenerateShortCommands="True" GeneratorGetMethodName="GetData" GeneratorSourceName="Fill" GetMethodModifier="Public" GetMethodName="GetData" QueryType="Rowset" ScalarCallRetval="System.Object, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" UseOptimisticConcurrency="True" UserGetMethodName="GetData" UserSourceName="Fill">
                <DeleteCommand>
                  <DbCommand CommandType="Text" ModifiedByUser="False">
                    <CommandText>DELETE FROM [dbo].[Authors] WHERE (([AuthorID] = @Original_AuthorID) AND ([Name] = @Original_Name))</CommandText>
                    <Parameters>
                      <Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@Original_AuthorID" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="AuthorID" SourceColumnNullMapping="False" SourceVersion="Original">
                      </Parameter>
                      <Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="@Original_Name" Precision="0" ProviderType="NVarChar" Scale="0" Size="0" SourceColumn="Name" SourceColumnNullMapping="False" SourceVersion="Original">
                      </Parameter>
                    </Parameters>
                  </DbCommand>
                </DeleteCommand>
                <InsertCommand>
                  <DbCommand CommandType="Text" ModifiedByUser="False">
                    <CommandText>INSERT INTO [dbo].[Authors] ([Name]) VALUES (@Name);
SELECT AuthorID, Name FROM Authors WHERE (AuthorID = SCOPE_IDENTITY())</CommandText>
                    <Parameters>
                      <Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="@Name" Precision="0" ProviderType="NVarChar" Scale="0" Size="0" SourceColumn="Name" SourceColumnNullMapping="False" SourceVersion="Current">
                      </Parameter>
                    </Parameters>
                  </DbCommand>
                </InsertCommand>
                <SelectCommand>
                  <DbCommand CommandType="Text" ModifiedByUser="False">
                    <CommandText>SELECT AuthorID, Name FROM dbo.Authors</CommandText>
                    <Parameters>
                    </Parameters>
                  </DbCommand>
                </SelectCommand>
                <UpdateCommand>
                  <DbCommand CommandType="Text" ModifiedByUser="False">
                    <CommandText>UPDATE [dbo].[Authors] SET [Name] = @Name WHERE (([AuthorID] = @Original_AuthorID) AND ([Name] = @Original_Name));
SELECT AuthorID, Name FROM Authors WHERE (AuthorID = @AuthorID)</CommandText>
                    <Parameters>
                      <Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="@Name" Precision="0" ProviderType="NVarChar" Scale="0" Size="0" SourceColumn="Name" SourceColumnNullMapping="False" SourceVersion="Current">
                      </Parameter>
                      <Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@Original_AuthorID" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="AuthorID" SourceColumnNullMapping="False" SourceVersion="Original">
                      </Parameter>
                      <Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="@Original_Name" Precision="0" ProviderType="NVarChar" Scale="0" Size="0" SourceColumn="Name" SourceColumnNullMapping="False" SourceVersion="Original">
                      </Parameter>
                      <Parameter AllowDbNull="False" AutogeneratedName="AuthorID" ColumnName="AuthorID" DataSourceName="Books.dbo.Authors" DataTypeServer="int" DbType="Int32" Direction="Input" ParameterName="@AuthorID" Precision="0" ProviderType="Int" Scale="0" Size="4" SourceColumn="AuthorID" SourceColumnNullMapping="False" SourceVersion="Current">
                      </Parameter>
                    </Parameters>
                  </DbCommand>
                </UpdateCommand>
              </DbSource>
            </MainSource>
            <Mappings>
              <Mapping SourceColumn="AuthorID" DataSetColumn="AuthorID" />
              <Mapping SourceColumn="Name" DataSetColumn="Name" />
            </Mappings>
            <Sources>
            </Sources>
          </TableAdapter>
          <TableAdapter BaseClass="System.ComponentModel.Component" DataAccessorModifier="AutoLayout, AnsiClass, Class, Public" DataAccessorName="BooksTableAdapter" GeneratorDataComponentClassName="BooksTableAdapter" Name="Books" UserDataComponentName="BooksTableAdapter">
            <MainSource>
              <DbSource ConnectionRef="BooksConnectionString (Settings)" DbObjectName="Books.dbo.Books" DbObjectType="Table" FillMethodModifier="Public" FillMethodName="Fill" GenerateMethods="Both" GenerateShortCommands="True" GeneratorGetMethodName="GetData" GeneratorSourceName="Fill" GetMethodModifier="Public" GetMethodName="GetData" QueryType="Rowset" ScalarCallRetval="System.Object, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" UseOptimisticConcurrency="True" UserGetMethodName="GetData" UserSourceName="Fill">
                <DeleteCommand>
                  <DbCommand CommandType="Text" ModifiedByUser="False">
                    <CommandText>DELETE FROM [dbo].[Books] WHERE (([BookID] = @Original_BookID) AND ([name] = @Original_name) AND ([Author] = @Original_Author))</CommandText>
                    <Parameters>
                      <Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@Original_BookID" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="BookID" SourceColumnNullMapping="False" SourceVersion="Original">
                      </Parameter>
                      <Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName="" DbType="AnsiString" Direction="Input" ParameterName="@Original_name" Precision="0" ProviderType="VarChar" Scale="0" Size="0" SourceColumn="name" SourceColumnNullMapping="False" SourceVersion="Original">
                      </Parameter>
                      <Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@Original_Author" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="Author" SourceColumnNullMapping="False" SourceVersion="Original">
                      </Parameter>
                    </Parameters>
                  </DbCommand>
                </DeleteCommand>
                <InsertCommand>
                  <DbCommand CommandType="Text" ModifiedByUser="False">
                    <CommandText>INSERT INTO [dbo].[Books] ([name], [Author]) VALUES (@name, @Author);
SELECT BookID, name, Author FROM Books WHERE (BookID = SCOPE_IDENTITY())</CommandText>
                    <Parameters>
                      <Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName="" DbType="AnsiString" Direction="Input" ParameterName="@name" Precision="0" ProviderType="VarChar" Scale="0" Size="0" SourceColumn="name" SourceColumnNullMapping="False" SourceVersion="Current">
                      </Parameter>
                      <Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@Author" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="Author" SourceColumnNullMapping="False" SourceVersion="Current">
                      </Parameter>
                    </Parameters>
                  </DbCommand>
                </InsertCommand>
                <SelectCommand>
                  <DbCommand CommandType="Text" ModifiedByUser="False">
                    <CommandText>SELECT BookID, name, Author FROM dbo.Books</CommandText>
                    <Parameters>
                    </Parameters>
                  </DbCommand>
                </SelectCommand>
                <UpdateCommand>
                  <DbCommand CommandType="Text" ModifiedByUser="False">
                    <CommandText>UPDATE [dbo].[Books] SET [name] = @name, [Author] = @Author WHERE (([BookID] = @Original_BookID) AND ([name] = @Original_name) AND ([Author] = @Original_Author));
SELECT BookID, name, Author FROM Books WHERE (BookID = @BookID)</CommandText>
                    <Parameters>
                      <Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName="" DbType="AnsiString" Direction="Input" ParameterName="@name" Precision="0" ProviderType="VarChar" Scale="0" Size="0" SourceColumn="name" SourceColumnNullMapping="False" SourceVersion="Current">
                      </Parameter>
                      <Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@Author" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="Author" SourceColumnNullMapping="False" SourceVersion="Current">
                      </Parameter>
                      <Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@Original_BookID" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="BookID" SourceColumnNullMapping="False" SourceVersion="Original">
                      </Parameter>
                      <Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName="" DbType="AnsiString" Direction="Input" ParameterName="@Original_name" Precision="0" ProviderType="VarChar" Scale="0" Size="0" SourceColumn="name" SourceColumnNullMapping="False" SourceVersion="Original">
                      </Parameter>
                      <Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@Original_Author" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="Author" SourceColumnNullMapping="False" SourceVersion="Original">
                      </Parameter>
                      <Parameter AllowDbNull="False" AutogeneratedName="BookID" ColumnName="BookID" DataSourceName="Books.dbo.Books" DataTypeServer="int" DbType="Int32" Direction="Input" ParameterName="@BookID" Precision="0" ProviderType="Int" Scale="0" Size="4" SourceColumn="BookID" SourceColumnNullMapping="False" SourceVersion="Current">
                      </Parameter>
                    </Parameters>
                  </DbCommand>
                </UpdateCommand>
              </DbSource>
            </MainSource>
            <Mappings>
              <Mapping SourceColumn="BookID" DataSetColumn="BookID" />
              <Mapping SourceColumn="name" DataSetColumn="name" />
              <Mapping SourceColumn="Author" DataSetColumn="Author" />
            </Mappings>
            <Sources>
            </Sources>
          </TableAdapter>
        </Tables>
        <Sources>
        </Sources>
      </DataSource>
    </xs:appinfo>
  </xs:annotation>

كده إنتهى الجزء الأول مع ملاحظة إن كله في ملف واحد و أنا فاصلهم للتوضيح فقط

  <xs:element name="BooksDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true" msprop:Generator_UserDSName="BooksDataSet" msprop:Generator_DataSetName="BooksDataSet">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="Authors" msprop:Generator_UserTableName="Authors" msprop:Generator_RowDeletedName="AuthorsRowDeleted" msprop:Generator_TableClassName="AuthorsDataTable" msprop:Generator_RowChangedName="AuthorsRowChanged" msprop:Generator_RowClassName="AuthorsRow" msprop:Generator_RowChangingName="AuthorsRowChanging" msprop:Generator_RowEvArgName="AuthorsRowChangeEvent" msprop:Generator_RowEvHandlerName="AuthorsRowChangeEventHandler" msprop:Generator_TablePropName="Authors" msprop:Generator_TableVarName="tableAuthors" msprop:Generator_RowDeletingName="AuthorsRowDeleting">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="AuthorID" msdata:ReadOnly="true" msdata:AutoIncrement="true" msprop:Generator_UserColumnName="AuthorID" msprop:Generator_ColumnPropNameInRow="AuthorID" msprop:Generator_ColumnVarNameInTable="columnAuthorID" msprop:Generator_ColumnPropNameInTable="AuthorIDColumn" type="xs:int" />
              <xs:element name="Name" msprop:Generator_UserColumnName="Name" msprop:Generator_ColumnPropNameInRow="Name" msprop:Generator_ColumnVarNameInTable="columnName" msprop:Generator_ColumnPropNameInTable="NameColumn">
                <xs:simpleType>
                  <xs:restriction base="xs:string">
                    <xs:maxLength value="50" />
                  </xs:restriction>
                </xs:simpleType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="Books" msprop:Generator_UserTableName="Books" msprop:Generator_RowDeletedName="BooksRowDeleted" msprop:Generator_TableClassName="BooksDataTable" msprop:Generator_RowChangedName="BooksRowChanged" msprop:Generator_RowClassName="BooksRow" msprop:Generator_RowChangingName="BooksRowChanging" msprop:Generator_RowEvArgName="BooksRowChangeEvent" msprop:Generator_RowEvHandlerName="BooksRowChangeEventHandler" msprop:Generator_TablePropName="Books" msprop:Generator_TableVarName="tableBooks" msprop:Generator_RowDeletingName="BooksRowDeleting">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="BookID" msdata:ReadOnly="true" msdata:AutoIncrement="true" msprop:Generator_UserColumnName="BookID" msprop:Generator_ColumnPropNameInRow="BookID" msprop:Generator_ColumnVarNameInTable="columnBookID" msprop:Generator_ColumnPropNameInTable="BookIDColumn" type="xs:int" />
              <xs:element name="name" msprop:Generator_UserColumnName="name" msprop:Generator_ColumnPropNameInRow="name" msprop:Generator_ColumnVarNameInTable="columnname" msprop:Generator_ColumnPropNameInTable="nameColumn">
                <xs:simpleType>
                  <xs:restriction base="xs:string">
                    <xs:maxLength value="50" />
                  </xs:restriction>
                </xs:simpleType>
              </xs:element>
              <xs:element name="Author" msprop:Generator_UserColumnName="Author" msprop:Generator_ColumnPropNameInRow="Author" msprop:Generator_ColumnVarNameInTable="columnAuthor" msprop:Generator_ColumnPropNameInTable="AuthorColumn" type="xs:int" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
    <xs:unique name="Constraint1" msdata:PrimaryKey="true">
      <xs:selector xpath=".//mstns:Authors" />
      <xs:field xpath="mstns:AuthorID" />
    </xs:unique>
    <xs:unique name="Books_Constraint1" msdata:ConstraintName="Constraint1" msdata:PrimaryKey="true">
      <xs:selector xpath=".//mstns:Books" />
      <xs:field xpath="mstns:BookID" />
    </xs:unique>
  </xs:element>
  <xs:annotation>
    <xs:appinfo>
      <msdata:Relationship name="FK_Authors_Books" msdata:parent="Authors" msdata:child="Books" msdata:parentkey="AuthorID" msdata:childkey="Author" msprop:Generator_UserRelationName="FK_Authors_Books" msprop:Generator_RelationVarName="relationFK_Authors_Books" msprop:Generator_UserChildTable="Books" msprop:Generator_UserParentTable="Authors" msprop:Generator_ParentPropName="AuthorsRow" msprop:Generator_ChildPropName="GetBooksRows" />
    </xs:appinfo>
  </xs:annotation>
</xs:schema>

تم تعديل هذه المشاركة بواسطة usama707 في 6 مايو 2006 في 14:47

#4

وعليكم السلام ورحمة الله وبركاته.

لا أعتقد أنه يوجد طريقه موجوده لمعرفة أو لانشاء XSD الخاصه بـ TableAdapter من خلال الأوبجكت بتاعه أثناء الـ Runtime !

وبالنسبه للـ XSD نفسها والأشياء المتعلقه بها فهي من اختصاص الـ W3C , ولكن المشكله أن ميكروسوفت تزود أشياء أخرى بجانب المعايير المتفق عليها. ولذلك ان لم تجد هناك معلومات كافيه عند ميكروسوفت عن هذا الأمر , فلن تجد في أي مكان آخر ... وعليك بالاجتهاد.

#Read

http://MoutazShams.blogspot.com

projects003.gif

أعتذر عن التغيب هذه الأيام نظرا للانشغال المريب

هذا الموضوع مغلق.

مواضيع مشابهة