Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.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# EntityFramework(.NET Core)由多个条件左外部联接_C#_Sql_Entity Framework_.net Core_Entity Framework Core - Fatal编程技术网

C# EntityFramework(.NET Core)由多个条件左外部联接

C# EntityFramework(.NET Core)由多个条件左外部联接,c#,sql,entity-framework,.net-core,entity-framework-core,C#,Sql,Entity Framework,.net Core,Entity Framework Core,我需要通过以下几个条件匹配用户和用户操作,操作类型,已批准,并且仍然希望将查询保留为左外部联接,因为操作可能丢失。在常规.net实体框架中,我将执行以下操作: var q = from u in db.User join ua in db.UserActions on { u.Id, "Approved" } equals { ua.UserId, ua.ActionType } into actions from ua in action.DefaultIfEm

我需要通过以下几个条件匹配
用户
用户操作
操作类型
已批准
,并且仍然希望将查询保留为
左外部联接
,因为操作可能丢失。在常规.net实体框架中,我将执行以下操作:

var q = from u in db.User
        join ua in db.UserActions on { u.Id, "Approved" } equals { ua.UserId, ua.ActionType } into actions
        from ua in action.DefaultIfEmpty()
        where u.Active
        select new { User = u, Actions = ua}
不幸的是,对于实体框架的核心版本,它不起作用。如何使用EF for.NET Core实现类似的目标?

试试以下方法:

var q = from u in db.User
    join ua in db.UserActions on new { UserId = u.Id, ActionType = "Approved" } equals new { ua.UserId, ua.ActionType } into actions
    from ua in actions.DefaultIfEmpty()
    where u.Active
    select new { User = u, Actions = ua}

连接语法两侧的匿名类型的属性名需要匹配。

您使用的是什么EF核心版本?收到了什么错误消息?