本文介绍了从ADO转换为实体框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将这段代码更改为实体框架
I need to change this piece of code to entity framework
string getQuerystring = queueListBox.Text.Substring(0, 4).Replace(" ", string.Empty);
queryString = "Select * from reservation where Id= '" + getQuerystring + "'";
query = new SqlCommand(queryString, connection);
我尝试过:
尝试将此更改为实体框架
What I have tried:
try to change this to entity framework
推荐答案
var result = myDbContext.Reservations.SingleOrDefault(r => r.Id == queryId);
或
or
var result = myDbContext.Reservations.Where(r => r.Id == queryId).SingleOrDefault();
或
or
var result = from r in myDbContext.Reservations
where r.Id == queryId
select r;
这篇关于从ADO转换为实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!