开发者

Is it possible in LINQ to SQL to create a computed column using DataContext.CreateDatabase?

I want to dynamically create a database using my DataContext's CreateDatabase Method. I have manually created mapping classes and tested them. But as soon as I add the Expression Column (see below) the creation fails with an SqlCeException and I am unable to find out the exact reason.

    /// <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; }

Omitting DbType or changing it to FLOAT didn't help, AutoSync.Always doesn't help either, omitting AutoSync and IsD开发者_如何学GobGenerated attributes doesn't work either. What am I doing wrong? Or is this simply not supported for a dynamically created db?


Linq to Sql is itself very poor in creating the whole database, at least, it does not create indecies, so the first thing you must do, is to store the SQL code which does and run it whenever you need to create a database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜