Click here to Skip to main content
15,885,195 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have 3 Tables

User Tabele

SQL
UserID UserName
1        Ma
2        Da
3        Ca
4        ga



EnterpriseApplication_User (Mapping Table)
SQL
ApplicationID USERID
2	       4
3	       4


EnterpriseApplication
SQL
ID NAME  APIKEY
1	A	ca822389
2	B	f1291236
3	C	2f098dfa
4	D	8911a9e5


I want to get the Subscribed Status for a specific user by join EnterpriseApplication table and the EnterpriseApplication_User table, It should be write by linq query in the code.

Subscribed Status : In this EnterpriseApplication_User Table the ApID 2 and 3 has subscribed to the UserID 4, I want to get the status coloumn as output with true for appID 2 and 3 , for the 1 and 2 Status false.

Output : For the userID 4
SQL
APID    APNAME  STAUS 
1	A     false
2	B     true
3	C     true
4	D     false
Posted
Updated 29-Oct-14 17:46pm
v2

I use this resource as first base when researching linq 101 Linq queries[^]
 
Share this answer
 
Comments
Gihan Liyanage 30-Oct-14 8:41am    
Thanx Mycroft. I will look on this
This is the solution. I got this from my senior

C#
List<enterpriseapplication> ReturnList = new List<enterpriseapplication>();

            IEnumerable<enterpriseapplicationdata> UserApplications = dbContext.RegisterApps.ToList();

            foreach (EnterpriseApplicationData UserApp in UserApplications)
            {
                EnterpriseApplication registerApp = new EnterpriseApplication { Id = UserApp.Id, Name = UserApp.Name, IsSubscribed=UserApp.Users.Any(u=>u.UserId==applicationUserId) };

                ReturnList.Add(registerApp);
            }

</enterpriseapplicationdata></enterpriseapplication></enterpriseapplication>
 
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