简体   繁体   English

实体框架3.5“查找”方法?

[英]Entity framework 3.5 “Find” method?

My app is stuck with win XP, I must convert it from EF 6 to EF 3.5 to compatible with net 3.5 In EF 5.x, I have 我的应用程序卡在Win XP上,我必须将其从EF 6转换为EF 3.5以与net 3.5兼容在EF 5.x中,

MyEntity db = new MyEntity();
int id = 1;
MyClass a = db.MyClasses.Find(id);

But in the old version ef 3.5, I can't find anything like that 但是在旧版ef 3.5中,我找不到类似的东西

The DbSet<T>.Find(id) method was introduced in Entity Framework 5.0 for DbContext, so it naturally is not available to you here. Entity Framework 5.0中为DbContext引入了DbSet<T>.Find(id)方法,因此在这里自然不可用。

That said, considering that early EF was built upon it's Linq 2 SQL predecessor, there's no reason you can't query your context directly. 就是说,考虑到早期的EF是基于Linq 2 SQL的前身构建的,因此没有理由不能直接查询上下文。

MyEntity db = new MyEntity();
int id = 1;
var result = db.MyClasses.FirstOrDefault(x => x.Id == id);

You can find Entity Framework 3.5 documentation of all available methods on MSDN. 您可以在MSDN上找到所有可用方法的Entity Framework 3.5文档

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

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