tags:

views:

10

answers:

1

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 missing, or should I abandon this idea?

+1  A: 

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));

Rob
Yeah thats what I think too. If there was a way to override or replace the LINQ methods (I mean I could write my own LINQ Provider?) it becomes to complicated. I'll let this sit for a day or two.
Erik Philips