Select data from multiple table with Entity Framework

I am able to select data from two tables, But I am getting partial result only while retrieving data from three tables.

var items = from orders in nobleappDbContext.JobOrders.Where(m => m.OrderStat == 0)
            join users in nobleappDbContext.users on orders.Uid equals users.Uid
            join customers in nobleappDbContext.customers on users.Uid equals customers.Uid into customdata
            from m in customdata.DefaultIfEmpty()
            select new
                   { 
                       Eid = orders.Eid, 
                       Uid = orders.Uid, 
                       OrderStat = orders.OrderStat, 
                       Name = m.Name, 
                       Contact = (m.Contact == null) ? 0 : m.Contact 
                   };
return Ok(items);

With this code, I am getting only result (common result) from users table and I am looking for something like UNION or OUTER JOIN.

Any help will be highly appreciated

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

finally I got exactly what I was looking for, here by posting the answer as I might help someone looking for same. LEFT JOIN with Entity Framework is the key

var query = from a in authurs
                         join b in books on a.Id equals b.AuthorId into auth_books
                         from left in auth_books.DefaultIfEmpty()
                         join bs in booksSeries on left.BookSeriesId equals bs.Id into books_bookseries
                         from left2 in books_bookseries.DefaultIfEmpty()
                         select new
                         {
                             Author = a.Name,
                             Book = left.Name,
                             BookSeries = left2.Description
                         };
                           
var resList2 = query.ToList();

refer this link for further clarification.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x