ado.net entity designer
TRANSCRIPT
-
8/3/2019 ADO.net Entity Designer
1/13
ADO.NET Entity Designer in Dot net Framework 4
Introduction:
An edmx file is an XML file that defines a conceptual model, a storage model, and the
mapping between these models. An edmx file also contains information that is usedby the ADO.NET Entity Data Model Designer (Entity Designer) to render a model
graphically
An edmx file can be included in the following Visual Studio project categories:
Application projects
Class libraries
Web projects
Framework Required: Dot net Framework 4.0
Steps to Create edmx file from existing database
Open a Project to which you want to create the edmx file.
-
8/3/2019 ADO.net Entity Designer
2/13
Right-click the project name in Solution Explorer, point to Add, and then click
New Item.
Select ADO.NET Entity Data Model in the Templates pane
Enter a proper name to the edmx file and click add button on the screen.
The first page of the Entity Data Model Wizard appears.
-
8/3/2019 ADO.net Entity Designer
3/13
If you want to create the edmx from existing database select Generate from
database and click next.
The second page of the Entity Data Model Wizard appears.
In this click New Connection from establishing a new connection withdatabase.
Select appropriate Data Source (in this case the data source is Microsoft SQL
Server)
Select the Server Name from the Dropdown list
Enter proper Authentication Method, with proper credentials.
And finally select the Data Base from the list. Test the Connection and Press OK
-
8/3/2019 ADO.net Entity Designer
4/13
The Second Page ofEntity Data Model Wizard will be visible with updated
information
You can find the Entity Connection String filled in with information like
metadata=res://*/Model1.csdl|res://*/Model1.ssdl|
res://*/Model1.msl;provider=System.Data.SqlClient;provider connectionstring="Data Source=WADB\SQLEXPRESS;Initial Catalog=WA_LOGDB;User
ID=nexus;Password=***********"
Clear/uncheck Save entity connection settings check box if you do not
want connection information saved in a configuration file.
Click Next
-
8/3/2019 ADO.net Entity Designer
5/13
The third page of the Entity Data Model Wizard appears.
Select the tables present in the Database from the tree Tables, Select viewand Stored Procedure from respective tree, and
Check Pluralize or singularize (it Controls whether new entity set names andnavigation property names are pluralized).
Click Finish.
You will get your edmx file in the project, with all connection to the tables.
Like this
-
8/3/2019 ADO.net Entity Designer
6/13
Right Click to the page on the designer, and select Add Code Generation
Item.
-
8/3/2019 ADO.net Entity Designer
7/13
You will get an Add new Item box, in that select ADO.NET Self Tracking
Entity Generator.
You will get a two files with extension .tt and .context.tt
-
8/3/2019 ADO.net Entity Designer
8/13
If the table name ends with s for e.g. SMS or TruckGPS the dot net willautomatically change its name to SM and TruckGP respectively as it eliminates the last s
from table name.
-
8/3/2019 ADO.net Entity Designer
9/13
In Such cases select the table from Entity Diagram, select the Property andchange the Name to appropriate Name of the Database. This will reset the Name of the
Table in all places including the file name.
You can have more than two Entity model in same project/ solution
-
8/3/2019 ADO.net Entity Designer
10/13
But for each entity and its sub file you should provide Custom Tool
Namespace.
This will differentiate the Name space for each entity as shown below.
Namespace Report
PartialPublicClassEntities
PublicSubNew(ByVal databaseConnectionInfo AsDatabaseConnectionInfo
MyBase.New(GetEntityFrameworkConnectionString(databaseConnectionInfo,
"Report"), ContainerName)
Initialize()
EndSubs
EndClassEndNamespace
Namespace Log
PartialPublicClassEntities
PublicSubNew(ByVal databaseConnectionInfo AsDatabaseConnectionInfo
MyBase.New(GetEntityFrameworkConnectionString(databaseConnectionInfo,
ContainerName)
Initialize()
EndSub
-
8/3/2019 ADO.net Entity Designer
11/13
EndClass
EndNamespace
This Process is for SQL Database for connecting it to other database for
example of our database is Oracle the connections have to be done manuallythrough SSDL and MSL file, for details see the figure below
Here in case of Oracle the Column names are case sensitive and thus have to
be manually changed to appropriate Upper Case
E.g. the EDMX file in case of SQL Connection will have:
Which will be Case sensitive in Oracle connection and have to be manually
changed to Upper Case:
And We have to separately modify the metaData
metaData = metaData.Replace(".ssdl", ".Oracle.ssdl")
metaData = metaData.Replace(".msl", ".Oracle.msl")
-
8/3/2019 ADO.net Entity Designer
12/13
Updating the Tables/ Views from the Model Browser
If the Data Base is updated with some new column you can always go to the
Model Browser and right click the Table/ Views in the Model Browser and SelectUpdate Model From Database.
-
8/3/2019 ADO.net Entity Designer
13/13
You will see the First page ofUpdate Wizard
Here you can see three tabs Add, Refresh, Delete
In Add Tab
You can see the Additional columns present in the Tables (Database).
You can select the columns and this will be added to the Entity model.
In Refresh Tab
Here you can see the Nodes for tables, views, and stored procedures that are
included in the existing model. Any changes that have been made to thesedatabase objects will be reflected in the updated storage model. Changes to the
conceptual model are made when columns are added to a table or view.
In Delete Tab
Here you can see the Nodes for tables, views, and stored procedure. If an object
is been deleted from the database and is present in the storage model, you can
expand the corresponding node. The objects in these nodes will be deleted from
the updated new model.