Database name: S
Table: STUDENT
ID NAME COUNTRYNO AGE BRANCHCODE
----------------------------------------
1 Alex 001 25 05
2 Mary 002 26 09
Database name: P
Table PERSON:
NAME COUNTRYNO AGE BRANCHCODE
------------------------------------------
John 127 45 04
Elize 125 54 06
I want to new table:
Database name: S
Table NEWPERSON
NAME COUNTRYNO AGE BRANCHCODE SITUATION
----------------------------------------------------
John 127 45 04 0
Elize 125 54 06 0
I want to compare the two tables (countryno
and branchcode
), and if I don't have the second table values, add them to the new table and situation get it 0.
But this code doesn't run. How to solve in Entity Framework?
var student=DbContext.Entities.Student.Select(a=> new { CountryNo =a.CountryNo, BranchCode=a.BranchCode
}); ------> //studentcount:0
var person=DbContext.Entities.Student.Select(a=> new { CountryNo =a.CountryNo, BranchCode=a.BranchCode
}); ----> //personcount:0
var common=person.Except(student); -----> //common:0
List<NEWPERSON> np= new List<NEWPERSON>(); ---> np:0
foreach(var item in common) //it doesnt enter loop
{
var ıtem=person.Single(persons=>persons.PERSON==item.PERSON && persons.CountryNo==item.CountryNo);
if(tempItem !=null)
{
NEWPERSON newperson=new NEWPERSON
{
CountryNo=item.CountryNo,
BranchCode=item.BranchCode,
Age=item.Age,
Name=item.Name,
Situation=0
}
np.Add(newperson);
}
}