c# – 如何在EF中指定左连接?

c# – 如何在EF中指定左连接?,第1张

概述我的模特: public partial class history_builds{ public int ID { get; set; } public int build { get; set; } public int br { get; set; } public int tag { get; set; } public string line { 我的模特:

public partial class history_builds{    public int ID { get; set; }    public int build { get; set; }    public int br { get; set; }    public int tag { get; set; }    public string line { get; set; }    public int rev { get; set; }    public int user_ID { get; set; }    public string distrib_path { get; set; }    public string setup_path { get; set; }    public System.DateTime build_date { get; set; }    public string product { get; set; }}public partial class history_uploads{    public int ID { get; set; }    public int ID_user { get; set; }    public string line { get; set; }    public int Build { get; set; }    public string distrib { get; set; }    public System.DateTime Time_upload { get; set; }    public int Status { get; set; }}public partial class user{    public int ID { get; set; }    public string name { get; set; }    public int ID_group { get; set; }}

语境:

public DbSet<history_builds> history_builds { get; set; }public DbSet<history_uploads> history_uploads { get; set; }public DbSet<user> users { get; set; }

我试着做这个Entity framework left join的左连接

var items = entitIEs.history_builds    .Join(        entitIEs.users.DefaultIfEmpty(),hb => hb.user_ID,u => u.ID,(hb,u) =>            new {                hb.distrib_path,hb.setup_path,hb.build_date,hb.build,User = (u == null ? String.Empty : u.name),hb.rev            }    )    .Join(entitIEs.history_uploads.DefaultIfEmpty(),hb => hb.build,hu => hu.Build,hu) =>            new HistoryBuIDItem {                Revision = hb.rev,Build = hb.build,distribPath = hb.distrib_path,SetupPath = hb.setup_path,BuildDate = hb.build_date,User = hb.User,Isupload = (hu == null ? true : false)            }    )    .Where(x => IDs.Contains(x.Revision))    .ToList();

但它不起作用,EF仍然发出内连接sql代码,有什么问题?

解决方法 左外连接示例:

from c in table0join o in table1 on c.sno equals o.sno into psfrom o in ps.DefaultIfEmpty()select new { c.name,o.number}

它渲染sql:

SELECT [t0].[name],[t1].[number] AS [number]FROM [table0] AS [t0]left OUTER JOIN [table1] AS [t1] ON ([t0].[sno]) = [t1].[sno]
总结

以上是内存溢出为你收集整理的c# – 如何在EF中指定左连接?全部内容,希望文章能够帮你解决c# – 如何在EF中指定左连接?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1223583.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-05
下一篇2022-06-05

发表评论

登录后才能评论

评论列表(0条)

    保存