简体   繁体   中英

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

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

The DbSet<T>.Find(id) method was introduced in Entity Framework 5.0 for DbContext, so it naturally is not available to you here.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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