我正试图通过 LINQ-SQL
. 我正在尝试以下方法
using(DataContext obj = new DataContext())
{
mdc_meters_data data = new mdc_meters_data();
data.cust_id = cust_id;
data.device_id = Convert.ToString(device_id);
data.kwh = Convert.ToString(e_val);
data.voltage_p1 = Convert.ToString(a_vol_val);
data.voltage_p2 = Convert.ToString(b_vol_val);
data.voltage_p2 = Convert.ToString(c_vol_val);
data.current_p1 = Convert.ToString(a_curr_val);
data.current_p2 = Convert.ToString(b_curr_val);
data.current_p3 = Convert.ToString(c_curr_val);
data.data_date_time = Convert.ToDateTime(theDate.ToString(format));
data.d_type = Convert.ToString(d_type);
data.pf1 = Convert.ToString(a_pf_val);
data.pf2 = Convert.ToString(b_pf_val);
data.pf3 = Convert.ToString(c_pf_val);
data.p_id = p_id;
// executes the commands to implement the changes to the database
obj.SubmitChanges();
}
我得到的错误是
“datacontext”不包含“submitchanges”的定义,并且找不到接受类型为“datacontext”的第一个参数的可访问扩展方法“submitchanges”
更新1
我做错了,所以我试着用继承的类来做 DbContext
班级。但不知什么原因,它仍然没有插入数据
using(mdc_dbEntities obj = new mdc_dbEntities())
{
mdc_meters_data data = new mdc_meters_data();
data.cust_id = cust_id;
data.device_id = Convert.ToString(device_id);
data.kwh = Convert.ToString(e_val);
data.voltage_p1 = Convert.ToString(a_vol_val);
data.voltage_p2 = Convert.ToString(b_vol_val);
data.voltage_p2 = Convert.ToString(c_vol_val);
data.current_p1 = Convert.ToString(a_curr_val);
data.current_p2 = Convert.ToString(b_curr_val);
data.current_p3 = Convert.ToString(c_curr_val);
data.data_date_time = Convert.ToDateTime(theDate.ToString(format));
data.d_type = Convert.ToString(d_type);
data.pf1 = Convert.ToString(a_pf_val);
data.pf2 = Convert.ToString(b_pf_val);
data.pf3 = Convert.ToString(c_pf_val);
data.p_id = p_id;
// executes the commands to implement the changes to the database
obj.SaveChanges();
}
暂无答案!
目前还没有任何答案,快来回答吧!