0

I am using Entity Framework where I want to fetch all the parent records which doesn't have child record.

How to query the same?

Parent Table -> "Messages" Child Table - > "SentMessages"

EDIT: Please note: I need th solution in Entity Framework classes.

Currently I am using -

ctx.Messages.Where(m => ctx.SentMessages(x => x.msgid != m.msgid)) 

but it failed

0

2 Answers 2

1

You can try this LINQ,

MessageList.Where(m => !SentMessageList.Select(sm => sm.MsgId).Contains(m.MsgId)); 
Sign up to request clarification or add additional context in comments.

3 Comments

how did you got MessageList?
MessageList is 'Messages' table record list, and SentMessageList is 'SentMessages' table record list, m.MsgId is 'Messages' table primary key, sm.MsgId is foreign key of Messages table in 'SentMessages' table.
@PareshMakwana you should have writen : ctx.Messages.Where(m => !ctx.SentMessages.Select(sm => sm.MsgId).Contains(m.MsgId));
0

in pseudo code:

from m in Messages where m.Sents.Count() == 0 select m 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.