0
如何在实体框架中设置外键值字段?我有卡特拉实体(与卡特拉表相关)。我需要简单的保存方法这一领域,但是,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的是未处理的用户代码
Duplicate:http://stackoverflow.com/questions/2577856/if-adding-new-entity-gives-error-me-entitycommandcompilationexception-was-unha – 2010-04-05 16:10:19