Click here to Skip to main content
15,900,258 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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?

What I have tried:

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);
    }
    
    }
Posted
Updated 14-Nov-18 11:06am
v2

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