views:

102

answers:

1

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: 

Upon you call ObjectContext.SaveChanges the generated ID will be in "kartlar" object:

using (GenSatisModuleEntities genSatisCtx = new GenSatisModuleEntities())
            {
                Kartlar kartlar = new Kartlar();
                //Do your stuff with kartlar...
                genSatisCtx.AddToKartlar(kartlar);
                genSatisCtx.SaveChanges();

                //kartlar.ID - the generated identifier should be loaded into ID property
            }

[updated]

List<Kartlar> kartAddedPatient;
 kartAddedPatient = (from k in genSatisCtx.Kartlar
                                    where k.Rehber.ID == RehberID &&
                                          k.Kampanya.ID == KampanyaID &&
                                          k.Birim.ID == BrimID
                                    select k).ToList()
 return kartAddedPatient ;

Regards,

Misha N.
you don't understand me Misha :) i can add some data foreign key field. But i need to learn what i added into Kartlar if i add RehberID(fkey), KampanyaID(fkey), BrimID(fkey), i should learn what i added i must learn new ID (primary key) in Kartlar...
programmerist
I understood from your question that you need to find out what is the id of newly generated record(kartlar) in database. Then, in your comment I see "must learn new ID(primary key) in Kartlar" which gives me same impression. So the new ID (primary key) will be loaded into property "ID" of object "kartlar" after executing Context.SaveChanges() (I guess that you have that property on Kartlar entity).
Misha N.
Yes you are correct! but i think that : "select * from Kartlar where RehberID=123 and KampanyaID=345 and BrimID=567 " i can write this query but how?
programmerist
Aha, I updated my answer... hope that this time I understood what you need :)
Misha N.
Thanks Misha: i wan you to add facebook . My name is yusuf karatoprak if you search me you can see me with beard. i wan to add msn : my msn : [email protected]
programmerist
[email protected]. Do you wan me to add msn?
programmerist