实体框架Context.SaveChanges()不在表中插入数据

时间:2013-06-03 12:12:20

标签: c# entity-framework-4

我正在使用Entity framework 4.1,我使用以下方法在表中插入数据,而不是在表中插入数据。

方法:

    private void InsertSMSStatus(Request request)
    {
        UtilitiesEntities context = new UtilitiesEntities();
        SMSAlertLog alertLog = new SMSAlertLog();
        alertLog.Recipients = request.To;
        alertLog.Sender = From;
        alertLog.Status = Convert.ToInt32(request.ResponseString);
        context.SaveChanges();
        context.Dispose();
    }

连接字符串:

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /></startup><connectionStrings><add name="UtilitiesEntities" connectionString="metadata=res://*/DataModel.SmsEntityModel.csdl|res://*/DataModel.SmsEntityModel.ssdl|res://*/DataModel.SmsEntityModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=bosql1srv;initial catalog=Utilities;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings></configuration>

任何想法?

1 个答案:

答案 0 :(得分:6)

您没有将实体添加到上下文中。

context.SMSAlertLogs.Add(alertLog); // name of entity set may change. It might not be SMSAlertLogs 
context.SaveChanges();