Veonik
asked on
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. PropertyAc cessor+Acc essor`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.
System.TypeLoadException: GenericArguments[2], 'System.Int32', on 'System.Data.Linq.Mapping.
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...
// ...
}
stacktrace.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER