0
어떻게 Entity Framework에서 설정된 외래 키 값 필드를 제공 할 수 있습니까? Kartlar 엔티티 (kartlar 테이블과 관련 있음)가 있습니다. 나는이 분야 있지만, RehberID, KAmpanyaId, BirimID가 키 foregin됩니다 ....Entity Framework의 외래 키 필드에 데이터를 추가하려면 어떻게합니까?
public static class SatisServicesUpdateTables
{
public static void SaveKartlar(int RehberID, int KampanyaID, int BrimID)
{
using (GenSatisModuleEntities genSatisKampanyaCtx = new GenSatisModuleEntities())
{
Kartlar kartlar = new Kartlar();
kartlar.RehberReference.EntityKey = new System.Data.EntityKey("genSatisKampanyaCtx.Rehber", "ID", RehberID);
kartlar.KampanyaReference.EntityKey = new System.Data.EntityKey("genSatisKampanyaCtx.Kampanya", "ID", KampanyaID);
kartlar.BirimReference.EntityKey = new System.Data.EntityKey("genSatisKampanyaCtx.Birim", "ID", BrimID);
kartlar.Notlar = "hfhfhfhfhfhfghfghfgfghk";
genSatisKampanyaCtx.AddToKartlar(kartlar);
genSatisKampanyaCtx.SaveChanges();
}
}
}
저장 방법 간단 필요하지만 나에게 던졌습니다 : ArgumentException이 사용자 코드에 의해 처리되지 않은했다
중복 : http://stackoverflow.com/questions/2577856/if-adding-new-entity-gives-error-me-entitycommandcompilationexception-was-unha –