Entity Framework联合查询该怎么书写

2025年05月07日 08:04
有1个网友回答
网友(1):

用HQL语句写就可以查出部分数据,
from p in entitys.Where(p => p.Id == 123) select p.Id
只查询对象的ID.

如果要查多字段的话
from p in entitys.Where(p => p.Id == 123) select new{id=p.id,name=p.name};
查出的数据会新建匿名对象.包含id,和name属性.

this.GridView1.DataSource=from p in entitys.Where(p => p.Id == 123) select new{id=p.id,name=p.name};