Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,

how can we use right outer join in c# linq.


here is my code


C#
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.
Posted
Comments
Oshtri Deka 28-Mar-14 3:35am    
Can you please improve your question?
Perhaps it too early for me, but I'm having trouble with reading your last sentence.

1 solution

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
}; 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900