重要-无法将带有linq的数据库中的记录添加到实体 [英] IMPORTANT --- Cant add record in database with linq to entity
本文介绍了重要-无法将带有linq的数据库中的记录添加到实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi
我有一个非常重要的问题,我已经与linq合作了很多次,但是这次我遇到了一个问题,我无法在数据库中保存任何记录!
这是我的代码的一部分
hi
i have a really important question , i''ve worked with linq to entity many times but this time i confront with a problem that i cant save any record in database!!!!!!
THIS IS A PART OF MY CODE
DatabaseEntities ndb = new DatabaseEntities();
M_Info mn = new M_Info();
mn.EDate = "m";
mn.LDay = "s";
mn.LHour = "s";
mn.MType = "slkd";
mn.SDate = "sajkc";
mn.Who = 1;
ndb.AddToM_Info(mn);
ndb.SaveChanges();
但是没有记录可以保存!!!!即使它没有抛出任何异常,我也不知道现在该怎么办
but no record will save!!!!! even it didnt throw any exeption, i donno what to do now
推荐答案
使用断点并调试应用程序,请仔细观察是否实际将记录保存在db中?
http://msdn.microsoft.com/en-us/library/gg509017.aspx [ ^ ]
谢谢,
Ambesha
use the breakpoints and debug the application , watch carefully that actulally you save records in db or not?
http://msdn.microsoft.com/en-us/library/gg509017.aspx[^]
Thanks,
Ambesha
尝试按照RajKumar的建议在M_Info上使用AddObject方法
例如:ndb.M_Info.AddObject(mn);
ndb.SaveChanges();
还要检查M_Info表是否具有主键.
Try using AddObject method on M_Info as suggested by RajKumar
e.g : ndb.M_Info.AddObject(mn);
ndb.SaveChanges();
Also check if the M_Info table has a primary key.
请使用此代码可能会解决您的问题:-
Hi,
Please use this code may it will solve your problem:-
using(DatabaseEntities ndb = new DatabaseEntities())
{
M_Info mn = new M_Info()
{
mn.EDate = "m",
mn.LDay = "s",
mn.LHour = "s",
mn.MType = "slkd",
mn.SDate = "sajkc",
mn.Who = 1,
};
ndb.AddToM_Info(mn);
ndb.SaveChanges();
}
这篇关于重要-无法将带有linq的数据库中的记录添加到实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文