如何取指定字段后组成实体类 linq to entity-CSDN论坛
1个回答
展开全部
效率上是有影响的
var ss = textcontext.Buy_booktb.where(b => b.bookid== bookid)
.select(b => new {b.bookid, b.bookname})
.FirstOrDefault();
但这样生成的是匿名类型,不能直接return了,因为返回类型对不上了
============
你要写个具体类
public class my
{
public int bookid;
public string bookname;
}
然后返回类型为my
my ss = textcontext.Buy_booktb.where(b => b.bookid == bookid)
.select(b => new my{bookid = b.bookid, bookname = b.bookname})
.FirstOrDefault();
return my;
var ss = textcontext.Buy_booktb.where(b => b.bookid== bookid)
.select(b => new {b.bookid, b.bookname})
.FirstOrDefault();
但这样生成的是匿名类型,不能直接return了,因为返回类型对不上了
============
你要写个具体类
public class my
{
public int bookid;
public string bookname;
}
然后返回类型为my
my ss = textcontext.Buy_booktb.where(b => b.bookid == bookid)
.select(b => new my{bookid = b.bookid, bookname = b.bookname})
.FirstOrDefault();
return my;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询