我有这个实体:
namespace Entities.dbo
{
[TableName("tbl_snapshot")]
public class Snapshot : AbstractEntity
{
[MapField("track")]
public int TrackId { get; set; }
[Association(CanBeNull = false, OtherKey = "id", ThisKey = "track")]
public Track Track { get; set; }
[MapField("snapshotnumber")]
public int SnapshotNumber { get; set; }
[MapField("data")]
public string Data { get; set; }
}}
我尝试将新的快照插入到这样的数据库中:
public static void XXX(Snapshot snapshot)
{
using (var db = new MyDbManager())
{
var s = new Snapshot
{
Id = snapshot.Id,
Data = snapshot.Data,
SnapshotNumber = snapshot.SnapshotNumber,
TrackId = snapshot.Track.Id
};
db.GetTable<Snapshot>().Insert(() => s);
}
}
你能看到有什么问题吗?我发送给XXX方法的快照如下所示:
(以JSON序列化):
{"TrackId":2,"Track":null,"SnapshotNumber":2,"Data":"030405","Id":3}
任何想法问题在哪里?
感谢
答案 0 :(得分:1)
问题是Bltoolkit的LinQ插入方法不支持常量值: db.GetTable()。Insert(()=&gt; s); s是一个常数值。
以下是您可以尝试的02种解决方案:
只是不要使用LinQ方法:
db.Insert(S);
http://yfilonov.blogspot.com/2012/10/linq-warkaround-for-bltoolkit-insert.html