Question

I am trying to create an Entity Data Model using the new U2 Toolkit .net U2.Data.Client.

I have gone through the EntityFrameWork example that already has a Customer.edmx file created which works fine.

I now want to create my own Entity Data Model but am unsure where to start.

I have tried creating an empty model and manually add my entities but am unsure how to link them to a table.

I have also tried to connect to a Univese database but unsure on how to connect to the database.

Any help please.

Was it helpful?

Solution

We are working on Visual Studio Add-ins for U2 Database. It will allow Server Explorer Integration and hence you can use DataSet Designer or EDM Designer. In Server Explorer, you will see Tables, Views and Subroutines. We will go EAP soon.

For now , you can do the following:

  • Create empty model.
  • From EDM Designer, drop one entity , give some name
  • Create two Properties, ID (int) and FirstName (string)
  • For example, Student, Students, ID, FirstName
  • Now , open the student.edmx file in XML Editor. For example, Right Click on student.edmx file and choose Open With->XML Text Editor
  • You will see SSDL, CSDL amd MSL
  • CSDL will have entity and two properties
  • SSDL and MSL should be Empty Now replace this line :

Schema xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl" Namespace="Model1.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2005"

with

Schema xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl" Namespace="Student.Store" Alias="Self" Provider="U2.Data.Client" ProviderManifestToken="UNIDATA, 07.02.0000"

  • In SSDL, add the following

            <EntityContainer Name="StudentTargetContainer" >
               <EntitySet Name="STUDENT" EntityType="Student.Store.STUDENT_NF_SUB"  />
           </EntityContainer>
      <EntityType Name="STUDENT">
          <Key>
              <PropertyRef Name="ID" />
    
          </Key>
          <Property Name="ID" Type="int" Nullable="false"  />
          <Property Name="FNAME" Type="varchar" MaxLength="25" />
    
      </EntityType>
    
  • Save the File.

  • Now double click student.edmx file to open in the Designer.
  • Time to time, you open student.edmx either in XML editor or EDM Designer. One content two views
  • Open Mapping Details Window. Right click on Entity -> Table Mapping
  • Map ID ->ID and FirstName-FNAME
  • Open App.config file and add the following

<add name="StudentContainer" connectionString="metadata=res://*/Student.csdl|res://*/Student.ssdl|res://*/Student.msl;provider=U2.Data.Client;provider connection string=&quot;Database=demo;User ID=user;Password=pass;Server=localhost;Persist Security Info=True;Pooling=False;ServerType=unidata&quot;" providerName="System.Data.EntityClient"/>

  • Open Program.cs file and add this LINQ Query

StudentContainer ctx = new StudentContainer(); var q =ctx.Students.ToList();

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top