【发布时间】:2014-03-23 06:49:16
【问题描述】:
您好,我有以下 ling 查询
var lst=(from p in db.business
where p.id == id
select new pO
{
pName = p.name,
newStructure = p.p_disc.Select(x=>
new newStructure
{
post_date=x.post_date,
posted_by_id=x.person.last_name.Where(x.posted_by_id==x.person.p_id)
})
});
newStructure 类是
public class newStructureProject
{
public int posted_by_id { get; set; }
public System.DateTime post_date { get; set; }
public person person { get; set; }
}
在下面的查询行中,我尝试使用 newStructure 中的 posted_by_id 从 person 表中读取姓氏和名字。
posted_by_id=x.person.last_name.Where(x.posted_by_id==x.person.p_id)
我收到 intelisense 错误“字符串不包含 where 的定义..... 请让我知道如何在查询中使用它来使用posted_by_id 来读取person 表中的姓氏和名字,它们具有外键关系。 谢谢
【问题讨论】:
-
实体是什么,它们之间的关系是什么?
-
你想在这里做什么?
posted_by_id=x.person.last_name.Where(x.posted_by_id==x.person.p_id) -
刚刚在帖子中添加了实体
-
基本上来自 p_disc 的 person_id 使用该 person_id 我正在从人(实体)读取人的姓名
-
您的查询选择了所需的帖子,不是吗?并且所需的帖子有一个人(导航属性),对吗?导航属性的目的是为您节省额外的外键搜索。我错过了什么吗?