开发者

Problems creating my own Custom DataAttribute for LinqToSql

I'm building LINQ Models by hand, because I want to (understand what's reall happening).

There is a great light weight tutorial on turning standard classes into Linq Models I am reading Here.

For my sample application I have created some models that look like:

public class LoginModel
{
    [Column(IsPrimaryKey=true, 
            DbType="UniqueIdentifier NOT NULL", 
            CanBeNull=false)]
    public Guid LoginID { get; set; }
    // .. and more question useless properties...
}

I'm definitely seeing a pattern for the primary key which led me to creating...

[AttributeUsage(AttributeTargets.Property
                | AttributeTargets.Field,
                AllowMultiple = false)]
public sealed class ColumnPrimaryKeyAttribute : DataAttribute
{
    public ColumnPrimaryKeyAttribute()
    {
        CanBeNull = false;
        IsPrimaryKey = true;
        DbType = "UniqueIdentifier NOT NULL";
    }
    // etc, etc...
}

So when I use my new Attribute, LINQ is not picking up my attribute (even though it inherits from the same DataAttribute as Column. Is there a step I'm 开发者_JAVA百科missing, or should I abandon this idea?


Try inheriting from ColumnAttribute...

public class ColumnPrimaryKeyAttribute : ColumnAttribute

Edit:

Never mind, I see that ColumnAttribute is sealed. You may be out of luck as my guess is LINQ is doing a System.Attribute.GetCustomAttributes(typeof(ColumnAttribute));

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜