3

I have a SQL query I want to write in LINQ

Here is my Query

SELECT DISTINCT * 
FROM [IHQDB].[dbo].[Table1] as t1 
inner join Table2 as t2 on t2.Table2 =t1.ChangedItemID 
inner join Table3 as t3 on t3.Table3 = t1.FromUserID 
where (t1.FromUserID=1 And t2.ContentItemID= t1.ChangedItemID) 
OR (t2.LastModifiedBy=1 or t2.CreatedBy=1 )

Hi now its working fine but My query little bit different on place of 1 I need my userID on base of their First Name and Last Name from M_User table. How can I get UserId on Base of First Name + Last Name.

Here is my LINQ CODE For Retrieving User Name

linq4 = from q in context.T_ContentItems
join p in context.M_Users on q.CreatedBy equals p.UserID 
where (advanceKeyword.Contains(p.EmployeeFirstName + " " + p.EmployeeLastName)) select q; 
advancechk12 = linq4.ToList();

========================================================================

What I require is that wherever I have written the value "1" (e.g. t2.CreatedBy=1), I need to find the UserID. For simplicity, I am able to get the names of all the filtered users in the advancechk12. How do I retrieve the UserID's of the list of usernames returned in advancechk12

2
  • 1
    Post your entity models as well.
    – Developer
    Commented Aug 27, 2016 at 7:31
  • Please ask your 2nd question on a new post.It's a new question.Then you'll have more feedback.
    – Sampath
    Commented Aug 27, 2016 at 9:50

1 Answer 1

1

You have to replace below mentioned Linq query with your models name.I just used the same name of the T-Sql.

 var t1List =   (from t1 in db.Table1
    join t2 in db.Table2 on t1.ChangedItemID equals t2.Id
    join t3 in db.Table3 on t3.Id equals t1.FromUserID
    where ((t1.FromUserID=1 && t2.ContentItemID= t1.ChangedItemID) || (t2.LastModifiedBy=1 or t2.CreatedBy=1))
    select t1).Distinct().ToList();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.