Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6888531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:01:49+00:00 2026-05-27T06:01:49+00:00

How to convert this one to LINQ? select d.UserID, d.Content, d.UpdateTime from DiaryPosts as

  • 0

How to convert this one to LINQ?

select d.UserID, d.Content, d.UpdateTime
from DiaryPosts as d
where d.UserID = 1
/* Friends posts */
Union
select d.UserID, d.Content, d.UpdateTime
from DiaryPosts as d
join Friends as fr 
on d.UserID = fr.FriendID 
where fr.UserID = 1
/* My followings */
Union
select d.UserID, d.Content, d.UpdateTime
from DiaryPosts as d
join Followers as fl 
on d.UserID = fl.FollowerID
where fl.UserID = 1
/* order by UpdateTime desc */
order by 3 desc

I tried this:

var diaryPosts = (from d in db.DiaryPosts
                           join e in db.EstadosDeAlma
                           on d.EstadosDeAlmaID equals e.ID
                           join u in db.User
                           on d.UserID equals u.ID
                           join fr in db.Friends
                           on d.UserID equals fr.FriendID
                           where fr.UserID == userset.ID
                           join fl in db.Followers
                           on d.UserID equals fl.UserID
                           where fl.FollowerID == userset.ID
                           orderby d.ID descending
                           select new DiaryPostsSet
                           {
                              PostID = d.ID,
                              EstadoDeAlmaID = e.ID,
                              EstadoDeAlma = e.Title,
                              Author = u.Nickname,
                              Thumbnail = u.Thumbnail,
                              AuthorComment = d.Content,
                              UserID = u.ID,
                              IsDuplicated = d.IsDuplicated,
                              FriendID = d.FriendID,
                              FriendName = u.Nickname,
                              Time = d.UpdateTime,
                              MessagesCount = d.FriendMessages.Count(m => m.DiaryPostsID == d.ID)
                          }).Take(6).ToList();

It doesn’t show me any result. I tried with EF clauses but when I have Union, I don’t know how to perform the next Join.

Could anyone help me please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:01:50+00:00Added an answer on May 27, 2026 at 6:01 am

    There is a Union Method in LINQ

    Here is a hint. When things get difficult break them down, then simplify. I will help you break down the problem and leave the simplification to you.

    var query1 = (from d in db.DiaryPosts
                  where d.UserID = 1
                  select new { 
                    UserID = d.UserID
                    Content = d.Content
                    UpdateTime = d.UpdateTime 
                  }).ToList();
    var query2 = (from d in db.DiaryPosts
                  join f in db.Friends
                  on d.UserId = f.FriendId
                  where f.UserId = 1
                  select new { 
                    UserID = d.UserID
                    Content = d.Content
                    UpdateTime = d.UpdateTime 
                  }).ToList();
    var query3 = (from d in db.DiaryPosts
                  join f in db.Followers
                  on d.UserId = f.FollowerID
                  where f.UserId = 1
                  select new { 
                    UserID = d.UserID
                    Content = d.Content
                    UpdateTime = d.UpdateTime 
                  }).ToList();
    
    var myunionQuery = query1.Union(query2).Union(query3).OrderBy(d => d.UpdateTime);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to convert this LINQ code var x = from nm in names
I have the following in linq-to-entities clientprojects = (from p in this.SAPMappingEntities.SAP_Master_Projects join c
I am new to LINQ, and I wish to convert from one datatype to
When using LINQ to get data from a list I encounter this error. How
I have the following Linq query: (from container in Container join containerType in ContainerType
I have this LINQ query: XNamespace ns = NAMESPACE; var items = (from c
How does one select a specific object using query-expression style Linq? private static ObservableCollection<Branch>
I am trying to convert the following SQL into NHibernate: SELECT * FROM dbo.Customer
I've been looking through related LINQ questions here trying to figure this one out,
How do you convert a SQL query with nested SELECT statements to a LINQ

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.