Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
If you have the difference in the following query, I want to look at these queries and print them with the message box. But if there is a difference, I cannot find the value as integer and I cannot print.

STUDENT TABLE

ALEX

JOHN

MARY

CLASS INFORMATION

ALEX


EXCEPT RESULT:
JOHN

MARY

I WANT TO:

MessageBox write JOHN,MARY IS NOT FOUND CLASS INFORMATION TABLE.

How to select and print a query in entity?

What I have tried:

C#
using Name=new HashSet<string>(studententities.Student.Select(x=>x.ID);
using Name2=new HashSet<string>(studententities.ClassInformation.Select(x=>x.ID));
var except=ID.Except(Name).ToList();

MessageBox.Show(except + "is not found class ınformation table");
Posted
Updated 26-Aug-19 9:29am
v5
Comments
Maciej Los 25-Aug-19 14:47pm    
Sorry, i don't get you... Does ID is a string field? Does ID means Name?
Member 14169626 25-Aug-19 15:03pm    
to summarize, I want to find the differences of the name fields in the two tables and print the differences with the message box

You are defining Name twice, so only the last statement is used.
See examples here: EXCEPT (Entity SQL) | Microsoft Docs[^]
c# - Get All Except from SQL database using Entity Framework - Stack Overflow[^]

For more information about the using statement, see: c# - using statement with multiple variables - Stack Overflow[^]
 
Share this answer
 
v2
Comments
Member 14169626 25-Aug-19 2:17am    
Hello there.Incorrectly defined.I corrected name2.I want to compare two names with the same values ​​from a different table.
RickZeeland 25-Aug-19 2:39am    
That's a step in the right direction :)
But I'm afraid I can't be of much help any further as I don't use Entity Framework myself, so hopefully some EF expert will help you further.
Member 14169626 25-Aug-19 5:42am    
Thank you for your help.
I'm not sure i understand you well, but...
Assuming that you want to find students which are not in ClassInformation table.

C#
var result = studententities.Student
    .Where(s => s.ID==some_id)
    .Select(s => s.Name)
    .Except(studententities.ClassInformation
        .Select(ci => ci.Name)
    .ToList();
//display names of unregistered students
foreach(string sname in result)
{
    Console.WriteLine(sname);
}
 
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