Problem with Mapping Linq-to-Sql on different Types

Posted by csharpnoob on Stack Overflow See other posts from Stack Overflow or by csharpnoob
Published on 2010-05-03T10:40:51Z Indexed on 2010/05/03 10:48 UTC
Read the original article Hit count: 702

Filed under:
|
|
|
|

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.

© Stack Overflow or respective owner

Related posts about linq-to-sql

Related posts about mapping