Tuesday, September 15, 2009

5 Simple Steps to add ado.net entity data Model in C# project

As I have started working on a C# with entity framework.A great tool from Microsoft to handle the databases through Entity framework. It’s amazing and definitely it will improve your confidence for database handling. It is so simple to implement ado.net entity data model in your C# project...
So let’s start to find the answer of - how can we connect a database with our c# project through entity framework?
In this example I am using the default database of Microsoft northwind.sdf.

1- At first open "add new item" dialog in project. Then select the ado.net entity data model(.edmx) option you can change the name of your data model as you like, here I am using the default name see in screen -1

Screen -1

2- When u create a data model then a dialog will appear with title "Entity Data model wizard", select option "Generate from database" and click on next button

Screen - 2

3- In next screen select new connection option and then a screen with "Connection properties" will appear, now click on change button and select database option for - Microsoft sql server compact, then click on browse button and select your database (default northwind.sdf its located in your Microsoft sql server compact edition folder) then click on ok see in screen – 3

Screen - 3

4- The wizard is automatically creating the required connection string for your database, click on next button -

Screen - 4

5- In next screen the tables of selected database is shown. Check it and then click on finish button see in screen - 5

Screen - 5

Finally the entity diagram of the required database and the tables are shown.

Screen - 6

You can also view the "app.config" xml file to view the connection string of your application –

Screen - 7

Now u can play with database easily.

Please tune in to get further tutorials regarding advanced filtering in queries, optimizing queries etc...

Reblog this post [with Zemanta]

No comments:

Post a Comment