简体   繁体   English

如何访问实体框架

[英]How to access the Entity Framework

I have mapped the database in the edmx file from the database. 我已经从数据库中将数据库映射到edmx文件中。 Now how do I use linq to make a query? 现在如何使用linq进行查询?

here is an example of my problem 这是我的问题的一个例子

var Found = from o in ??????

What suppose to go in the question marks. 问号中应该包含的内容。 How do I find what suppose to go in the question marks. 如何找到问号中应该包含的内容。 I have tried many tutorials but that do not tell you exactly how to use Linq. 我已经尝试了许多教程,但是并没有确切告诉您如何使用Linq。

Well, Entity Framework generates an ObjectContext for you. 好了,实体框架会为您生成一个ObjectContext。 You should know the name of your ObjectContext class. 您应该知道ObjectContext类的名称。 Then to query using LINQ you can do something line that 然后要使用LINQ进行查询,您可以执行以下操作:

using(var context = new NorthwindContext())
{
   var query = from p in context.ProductsSet select p;
   // then loop through your query instance.
}

The above example is very simple you should have a look at http://thedatafarm.com/blog/ for better tutorials 上面的示例非常简单,您应该查看http://thedatafarm.com/blog/以获取更好的教程

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

相关问题 如何使用Entity Framework访问子表 - How to access child tables with Entity Framework 如何使用Entity Framework 6访问Middleware中的数据库 - How to access the database in Middleware using Entity Framework 6 如何在ASP.NET实体框架中访问旧实体值 - How to access old entity value in ASP.NET Entity Framework 如何使用实体框架在上下文之外访问实体的属性? - How to access entity's properties outside context using Entity Framework? 实体框架数据访问 - Entity Framework data access 在实体框架中访问 Model - Access to Model in Entity Framework 实体框架4.1:创建新实体后如何访问虚拟实体属性? - Entity Framework 4.1: How can I access virtual entity properties after creating a new entity? 使用实体框架,如何访问与每个办公室(另一个实体)相对应的雇员数量(一个实体)? - Using Entity Framework, how do I access the number of employees (one entity) corresponding to each office (another entity)? 实体框架核心-如何访问Context.Database.Migrate() - Entity Framework Core - How To Access Context.Database.Migrate() 如何在ASP MVC和实体框架中访问另一个控制器的视图 - How to access to views of another Controller in ASP MVC and Entity Framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM