Problem with Mapping Linq-to-Sql on different Types
- by csharpnoob
Hi,
maybe someone can help.
I want to have on mapped Linq-Class different Datatype.
This is working:
private System.Nullable<short> _deleted = 1;
[Column(Storage = "_deleted", Name = "deleted", DbType = "SmallInt", CanBeNull = true)]
public System.Nullable<short> deleted
{
get
{
return this._deleted;
}
set
{
this._deleted = value;
}
}
Sure thing. But no when i want to place some logic for boolean, like this:
private System.Nullable<short> _deleted = 1;
[Column(Storage = "_deleted", Name = "deleted", DbType = "SmallInt", CanBeNull = true)]
public bool deleted
{
get
{
if (this._deleted == 1)
{
return true;
}
return false;
}
set
{
if(value == true)
{
this._deleted = (short)1;
}else
{
this._deleted = (short)0;
}
}
}
I get always runtime error:
[TypeLoadException: GenericArguments[2], "System.Nullable`1[System.Int16]", on 'System.Data.Linq.Mapping.PropertyAccessor+Accessor`3[T,V,V2]' violates the constraint of type parameter 'V2'.]
I can't change the database to bit.. I need to have casting in mapping class.