异常信息
1 | EntityFramework |
单从这个信息是看不出来具体原因的。需要在出错的代码上加 try 并捕获 DbEntityValidationException1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41private static void add(rt_blacklist bl)
{
try
{
using (RateEntityContext ctx = new RateEntityContext())
{
rt_blacklist_his blh = new rt_blacklist_his();
blh.biz_id = bl.biz_id;
blh.buyer_nick = bl.buyer_nick;
blh.sync_time = 0;
blh.operate_type = 1;
blh.is_sync = 0;
blh.created = TimeHelper.GetNowTimeToStamp();
ctx.rt_blacklist_his.Add(blh);
ctx.rt_blacklist.Add(bl);
ctx.SaveChanges();
}
}
catch (DbEntityValidationException ex)
{
string error = string.Empty;
foreach (var eveItem in ex.EntityValidationErrors)
{
foreach (var veItem in eveItem.ValidationErrors)
{
error = string.Format("{0}:{1}\r\n", veItem.PropertyName, veItem.ErrorMessage);
}
}
//Console.WriteLine(error);
LogHelper.WriteLog(error, errLogFileName);
}
catch (Exception e)
{
string err = e.InnerException.InnerException.Message;
//Console.WriteLine(err);
LogHelper.WriteLog(err, errLogFileName);
}
}
捕获到的信息:buyer_nick:字段 buyer_nick 必须是最大长度为 45 的字符串。