Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
NEW DATABASE NAME: NEWSTUDENT_1 
TABLENAME : Teacher
        
    
        ID    NAME   BRANCHCODE   NUMBER    COUNTRYCODE    COURSECODE
        012   Emily    01          123         0101              20
        104   Alex     02          124          021              23
        109   Toms     02          245          015              54
        145   Michael  06          458          053              26

    
NEW DATABASE NAME: NEWSTUDENT_2 
TABLENAME : STUDENT
    
    ID    NAME    BRANCHCODE    NUMBER    COUNTRYCODE    COURSECODE
    002   Hill        036        1225         0101           20
    109   Toms        02         245          0217           29
    
NEW DATABASE NAME:  NEWSTUDENT_2 
TABLENAME : STUDENTINFORMATION
    
    COUNTRYCODE  COURSECODE    COURSENAME    COURSEADDRESS
     0101            20           ASD         4.Ave B.APT
     0217            29           TYA         5.Ave T.APT
    
    
   **I WANT TO EXCEPT AND INSERT TABLE RESULT EXAMPLE:**

  

DATABASE NAME: NEWSTUDENT_1
TABLENAME : Country
        
        
        COUNTRYCODE   COURSECODE    COURSENAME   COURSEADDRESS    STATUS
          0101           20            ASD       4.Ave B.APT       0
          0217           29            TYA       5.Ave T.APT       0


What I have tried:

TRY QUERY:

 
      public static void Compare()
    {
         var Teacher=DbContext.Entities.Teacher.Select(p=>new {p.CountryCode,p.BranchID}
         var Student=DbContext.Entities.Teacher.Select(p=>new {p.CountryCode,p.BranchID}
         var common=Country.Except(Teacher);
    
    List<Country> t=new List<Country>();
    
    foreach(var p in common)
    {
         var ıtem=teacher.SingleOrDefault(s=>s.CountryCode==p.CountryCode && s.BranchCode==p.BranchCode);
    if(ıtem==null)
    {
         Country  ctable= new Country
    {
         BranchID=ıtem.BranchID,
         CountryCode=ıtem.BranchID,
         CountryInf=ıtem.CountryInf,
         Status=0
    };
    t.Add(ctable);
    }
    }
    DbContext.Entities.Country.AddRange(t);
    DbContext.Entities.SaveChanges();
    }

Can you help me with this?How to write except and insert query?
Posted
Comments
[no name] 13-Nov-18 17:03pm    
First of all: Thumbs up you added source code. But please try to describe the Problems also in words. What have you done, what you expect and what you get....

Your subject:"How to tables insert use entitiy in C#?"
Is it not more ""How two tables ...."?

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