LINQ to SQL throwing exception when IsPrimaryKey = true

I have manually created a LINQ to SQL entity, however when I specifiy IsPrimaryKey = true, I get this exception:

System.TypeLoadException: GenericArguments[2], 'System.Int32', on 'System.Data.Linq.Mapping.PropertyAccessor+Accessor`3[T,V,V2]' violates the constraint of type parameter 'V2'.


The exception is thrown any time a User entity is attempted to be used, for ex. DataContext.GetTable<User>()

The column is defined correctly as the primary key in SQL server. There are other entities which have Primary Keys set up exactly this way and they work just fine.

If I drop the IsPrimaryKey decoration, it generally works fine... except you cant Update, Insert or Delete without a primary key ;)


See the attached file for the stack trace.
[Table(Name="Users")]
public partial class User
{
    [Column(IsPrimaryKey = true, Name = "UserID", IsDbGenerated = true, AutoSync = AutoSync.OnInsert, DbType = "int NOT NULL IDENTITY")]
    public int ID { get; set; }

    // more columns, methods, etc...
    // ...
}

Open in new window

stacktrace.txt
VeonikAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SriVaddadiCommented:
Seems like there is something wrong with your mapping. Verify the xml mapping file for this entity object and other entities with primary key and you should be able to fix it.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VeonikAuthor Commented:
I took your advice and kept trying different things. There was a problem mapping one of the properties to the database.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.