Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在子查询中使用Linq从一个表中使用id从另一个表中读取值_C#_Mysql_Sql_Linq_Lambda - Fatal编程技术网

C# 在子查询中使用Linq从一个表中使用id从另一个表中读取值

C# 在子查询中使用Linq从一个表中使用id从另一个表中读取值,c#,mysql,sql,linq,lambda,C#,Mysql,Sql,Linq,Lambda,嗨,我有以下问题 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

嗨,我有以下问题

 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)
I get IntelliSense错误字符串不包含where…..的定义。。。。。 请让我知道如何在我的查询中使用posted_by_id来读取person表中的姓和名,它们有外键关系。
谢谢

试试这个姓氏

posted_by_id=x.person.Where(x=>x.posted_by_id==x.person.p_id).Select(x=>x.last_name).FirstOrDefault()

您需要首先在对象上应用where子句,然后选择所需的属性值。

实体是什么,它们之间的关系是什么?您在这里想做什么?posted_by_id=x.person.last_name.Wherex.posted_by_id==x.person.p_id刚刚在post中添加了实体基本上是从p_disc有person_id使用该person_id我正在从person entity读取person的姓名您的查询选择了所需的post,不是吗?所需的职位有personnavigation属性,对吗?导航属性的目的是为您保存对外键的额外搜索。我是不是错过了什么?Intelissense不会让我选择和x.person在一起的地方