1
我想用我的DataContext的CreateDatabase方法動態地創建一個數據庫。我已經手動創建了映射類並進行了測試。但是,一旦我添加表達式列(見下文),創建將失敗並出現SqlCeException,我無法找到確切的原因。是否有可能在LINQ to SQL中使用DataContext.CreateDatabase創建計算列?
/// <summary>
/// The sum of ratings for this document.
/// </summary>
[Column]
public Nullable<float> RatingSum { get; set; }
/// <summary>
/// The number of times the document was rated.
/// </summary>
[Column]
public Nullable<float> RatingCount { get; set; }
/// <summary>
/// Average rating as calculated from RatingSum and RatingCount
/// </summary>
[Column(AutoSync=AutoSync.Never, IsDbGenerated=true, Expression = "RatingSum * RatingCount", DbType="REAL")]
public Nullable<float> Rating { get; set; }
的省略的DbType或將其更改爲FLOAT沒有幫助,AutoSync.Always並沒有幫助,省略了自動同步和IsDbGenerated屬性也不管用。我究竟做錯了什麼?或者這只是不支持動態創建的數據庫?