本文介绍了linq的右外连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 HI, 我们如何在c#linq中使用右外连接。 这是我的代码 var selArticles =( from p in eLibObj.Publications join eLibObj.publicationID上的文章等于a.PublicationID eLibObj.ArticleReadUnreads.Where(atrxn = > join ar a.ArticleID上的/ span> ampxn.EmployeeID.Equals(iEmployeeID))等于ar.ArticleID 进入 gj 来自 newList gj.DefaultIfEmpty() 其中 p.Enabled.Equals( true )&& ; a.Published.Equals( 1 )&& a.Enabled.Equals( true ) select new { ArticleID = a.ArticleID, Title = a.Title, PublicationID = a.PublicationID, PublicationImage = p.ImageName, ArticleDate = a.ArticleDate, PublicationName = p.Name, ArticleTRXNID = newList.ArticleID == null ? 0 :newList.ArticleID, ArticleLastReadTime = newList.LastReadTime == null ? new DateTime( 1900 , 1 , 1 ):newList.LastReadTime })。ToList()。OrderByDescending(o = > o.ArticleLastReadTime).Take( 4 ); 首先我获得所有发表文章,然后想要匹配所有文章empid和读取,并希望从文章中只获得前四个记录。目前发生的情况是它加载所有文章以供发布,并且如果没有数据匹配,则使用readunread表离开外连接,因为左外连接仍然获得前4条记录。解决方案 你可以尝试这个......根据你的要求安排表格和列名。 var CategoriesAndProducts = 来自类别的类别 join 类产品中的产品等于product.Category into categoryProducts 来自categoryProducts.DefaultIfEmpty()类别选择新 { product.productname, product.productID }; HI,how can we use right outer join in c# linq.here is my code var selArticles = (from p in eLibObj.Publications join a in eLibObj.Articles on p.PublicationID equals a.PublicationID join ar in eLibObj.ArticleReadUnreads.Where(atrxn => atrxn.EmployeeID.Equals(iEmployeeID)) on a.ArticleID equals ar.ArticleID into gj from newList in gj.DefaultIfEmpty() where p.Enabled.Equals(true) && a.Published.Equals(1) && a.Enabled.Equals(true) select new { ArticleID = a.ArticleID, Title = a.Title, PublicationID = a.PublicationID, PublicationImage = p.ImageName, ArticleDate = a.ArticleDate, PublicationName = p.Name, ArticleTRXNID = newList.ArticleID == null ? 0 : newList.ArticleID, ArticleLastReadTime = newList.LastReadTime == null ? new DateTime(1900, 1, 1) : newList.LastReadTime }).ToList().OrderByDescending(o => o.ArticleLastReadTime).Take(4); first i get all articles for publication and then want to match all articles with empid and are read and from that want to get only top four records from article. currently what happen that it loads all articles for publication and do left outer join with readunread table if no data match still it gets first 4 records because of the left outer join. 解决方案 you can try this.... arrange table and column name according to your requirement.var CategoriesAndProducts = from category in Categories join product in Products on category equals product.Category into categoryProducts from category in categoryProducts.DefaultIfEmpty()select new { product.productname, product.productID}; 这篇关于linq的右外连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-16 10:45