简体   繁体   English

如何仅通过添加ADO.NET实体数据模型ASP.NET MVC 3连接到SQL Server数据库和获取数据

[英]How to Connect to SQL Server Database and Fetch datas by Just adding ADO.NET Entity Data model ASP.NET MVC 3

Im new to Asp.net MVC 3 and my boss wants me to remove the "SELECT/UPDATE/ DELETE SQL Query Statements" and recommend me to use ADO.NET Entity but my question is. 我是Asp.net MVC 3的新手,老板希望我删除“ SELECT / UPDATE / DELETE SQL查询语句”,并建议我使用ADO.NET实体,但我的问题是。 . how can i map and fetch the datas in the database by just calling the DataContext. 我如何仅通过调用DataContext即可映射和获取数据库中的数据。 . Thanks! 谢谢!

  1. Right click on your Project and select add new Item. 右键单击您的项目,然后选择添加新项目。 from Add New Item and select "ADO.net Entity Data model". 从添加新项,然后选择“ ADO.net实体数据模型”。 Give the name and all necessary things, attach your DB and signing credentials. 输入名称和所有必要的内容,附加数据库并签署凭据。 after finishing a .edmx file will add at your project. 完成.edmx文件后,将添加到您的项目中。
  2. open the edmx file and right click on the design view and select "add Code Generation item". 打开edmx文件,然后在设计视图上单击鼠标右键,然后选择“添加代码生成项”。 Add new Item panel appears. 出现“添加新项目”面板。 from the panel select "ADO.net DbContext Generator". 从面板中选择“ ADO.net DbContext Generator”。 give the name and add it. 给出名称并添加它。
  3. Crete a object of DbContext Class. 克里特岛DbContext类的对象。 use that DbContex Object methods to insert/Update/Delete command to do your job. 使用该DbContex对象方法插入/更新/删除命令来完成您的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM