Click here to Skip to main content
15,861,125 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I tried LINQ querying my entity model/database to get the PK_ID by using the FK_ID of the same table.

C#
var sessid = attend.tblSessions.Where(u => u.FK_GroupID == id).Select(u => u.PK_SessionsID);

MessageBox.Show(sessid.ToString());


attend is the model
id is supplied by other means and is the correct value that is needed.

when the message box displays it gives me
SELECT
[Extent1].[PK_SessionsID] AS [PK_SessionsID]
FROM [dbo].[tblSessions] AS [Extent1]
WHERE [Extent1].[FK_GroupID] = @p__linq__0


and not the value of the PK_ID

Any help will be greatly appreciated...
Posted

1 solution

There is one or more records not displayed in messageBox


Where(u => u.FK_GroupID == id).Select(u => u.PK_SessionsID)


Try This

var sessid = attend.tblSessions.Where(u => u.FK_GroupID == id).Select(u => u.PK_SessionsID).FirsrOrDefault();

MessageBox.Show(sessid.ToString());


or

See what type will return with sessid
 
Share this answer
 
Comments
D3m0n1CMoNkEy 15-May-13 6:22am    
Cool it worked, gave me the correct PK_ID, Thank you...but what if there is more than 1 record in the model/database, from what i understand the FirstOrDefault only takes the first record shown...am i right?
D3m0n1CMoNkEy 15-May-13 6:31am    
Wait...Scratch that comment, im being stupid...thanks for your help sixthplanets

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