Example 1:
Generating Model from Database
File->New project
· In the Solution Explorer right-click on the project and choose Add | New Item.
· In the dialog choose ADO.NET Entity Data Model, click Add. This launches Entity Data Model Wizard.
Click on New Connection.
Click on OK Button.
Click on Next Button.
select the table and click on finish.
Go to Program.cs and write the following code
Output
MYDBEntities
Is the name of the class that knows all about your model and does everything to handle it.Entity Framework operations are performed within this class's properties and methods. It is recommended that you keep a single instance of the class throughout your application because it consumes lots of resources. · Query, it - these are arbitrary variable names in the LINQ to Entities statement. The former is used as the collection of data objects, the latter is not used outside the statement. · Emp (in the for each statement) is the name of an auto generated class. This class maps to the company table in the database and is named after it.
· In the Solution Explorer right-click on the project and choose Add | New Item.
· In the dialog choose ADO.NET Entity Data Model, click Add. This launches Entity Data Model Wizard.
Click on New Connection.
Click on OK Button.
Click on Next Button.
select the table and click on finish.
Output
MYDBEntities
Is the name of the class that knows all about your model and does everything to handle it.Entity Framework operations are performed within this class's properties and methods. It is recommended that you keep a single instance of the class throughout your application because it consumes lots of resources.
· Query, it - these are arbitrary variable names in the LINQ to Entities statement. The former is used as the collection of data objects, the latter is not used outside the statement.
· Emp (in the for each statement) is the name of an auto generated class. This class maps to the company table in the database and is named after it.
No comments:
Post a Comment
Thank you for visiting my blog