我正在使用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="data source=bosql1srv;initial catalog=Utilities;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings></configuration>
任何想法?
答案 0 :(得分:6)
您没有将实体添加到上下文中。
context.SMSAlertLogs.Add(alertLog); // name of entity set may change. It might not be SMSAlertLogs
context.SaveChanges();