views:

92

answers:

1

I have a table it includes 3 foreign key field like that:

My Table: Kartlar

  • ID (Pkey)
  • RehberID (Fkey)
  • KampanyaID (Fkey)
  • BrimID (Fkey)
  • Name
  • Detail

How can i write entity query with linq :?

select * from Kartlar where RehberID=123 and KampanyaID=345 and BrimID=567

BUT please be careful I can not see RehberID, KampanyaID, BrimID in entity they are foreign keys. I should use entity key but how?

My Entity:

Addding data into kartlar Table (RehberID, KampanyaID, BrimID) is ok. But which Kart'ID created? I need to learn which Id created after adding data (RehberID,KampanyaID,BrimID) into Kartlar?

public static List<Kartlar> SaveKartlar(int RehberID, int KampanyaID, int BrimID, string Notlar)
{
    using (GenSatisModuleEntities genSatisCtx = new GenSatisModuleEntities())
    {
       Kartlar kartlar = new Kartlar();
       kartlar.RehberReference.EntityKey = new System.Data.EntityKey("GenSatisModuleEntities.Rehber", "ID", RehberID);
       kartlar.KampanyaReference.EntityKey = new System.Data.EntityKey("GenSatisModuleEntities.Kampanya", "ID", KampanyaID);
       kartlar.BirimReference.EntityKey = new System.Data.EntityKey("GenSatisModuleEntities.Birim", "ID", BrimID);
       kartlar.Notlar = Notlar;
       genSatisCtx.AddToKartlar(kartlar);
       genSatisCtx.SaveChanges();
       List<Kartlar> kartAddedPatient;
       kartAddedPatient = (from k in genSatisCtx.Kartlar
                           where k.RehberReference.EntityKey == RehberID &&
                                 k.KampanyaReference.EntityKey == KampanyaID &&
                                 k.BirimReference.EntityKey == BrimID
                           select k)
   return kartAddedPatient ;
    }
}

How can I do that? I want to get data from Kartlar which data I added?

A: 
genSatisCtx.AddToKartlar(kartlar);
genSatisCtx.SaveChanges();
int newKartlarID = kartlar.KartID;//kartID or whatever you call your primary key
return newKartlarID;

after you save the object kartlar it gets a primary key that can be used afterwords hopefully this helps and also what language is kartlar????

Laurence Burke
Please give me some feedback I would like to see if this helps you or not
Laurence Burke
using (GenSatisModuleEntities genSatisCtx = new GenSatisModuleEntities()) {genSatisCtx. ObjectTrackingEnabled ----> not included Thanks...}
programmerist
well did it work???
Laurence Burke
no it is not working. Laurence how cani do that?
programmerist
programmist can you give me the entity you want it to ouptut and the other table structures that you have
Laurence Burke
ok i will refreshed my ques in 4 minutes..
programmerist
i rearranged my question Laurece please look it sir :)
programmerist
updated the code thanks for the clarification
Laurence Burke
After Save event send KartId last one???? it is great if it is real. it must be magic
programmerist
it is I know I have a previous question on this that I asked myself http://stackoverflow.com/questions/2433333/scope-identity-with-linqalso hit me up with a selected answer if it works for you
Laurence Burke
ok; how to use write select statement wity EntityKey? i really want to learn!!! Laurance By the way i added you facebook ;)
programmerist
Actually I am not to sure about entity keys I am not familiar with them at all so I am sorry I cant help you with that but I hope at least I solved your immediate problem with the newly created kartlar entity.
Laurence Burke
by the way Proggramist you might have added my father instead of me to your friends in facebook my name in facebook is larry burke
Laurence Burke
My Name is Yusuf Karatoprak : my msn : [email protected] add me please
programmerist
i don't find you facebook : larry burke i am Yusuf Karatoprak. if you searched me you can see me above page with beard ;)
programmerist
I just requested to add you
Laurence Burke