使用 LINQ 插入数据库行时,a 0
(as an int
) 被转换为NULL
并且不会显示在插入语句中:
DatabaseCAMAE db = new DatabaseCAMAE(Database.Instance.Connection);
db.Log = Console.Out;
camaeprotocol cpr = new camaeprotocol
{
sid = 0,
prrevision = 0,
ataction = "Scan created",
prdescription = "Scan created",
prtimestamp = DateTime.Now,
uid = 0
};
db.camaeprotocol.InsertOnSubmit(cpr);
db.SubmitChanges();
Wheresid
和prrevision
是主键。
日志输出:
INSERT INTO "main"."camae_protocol"
("at_action", "pr_description", "pr_timestamp", "u_id")
VALUES (:ataction, :prdescription, :prtimestamp, :uid)
-- :ataction: Input String (Size = 0; Prec = 0; Scale = 0) [Scan created]
-- :prdescription: Input String (Size = 0; Prec = 0; Scale = 0) [Scan created]
-- :prtimestamp: Input DateTime (Size = 0; Prec = 0; Scale = 0) [16.04.2013 07:52:44]
-- :uid: Input Int32 (Size = 0; Prec = 0; Scale = 0) [0]
-- Context: SQLite Model: AttributedMetaModel Build: 0.20.0.0
并引发异常(违反约束),因为 LINQ 不会尝试插入0
sid
and 0
prrevision
。该怎么做才能解决这个问题?