Error Details:
(18,12) : error 2019: Member Mapping specified is not valid. The type 'Edm.Byte[Nullable=False,DefaultValue=]' of member 'status' in type 'IMS.DAL.Users_mast' is not compatible with 'SqlServer.binary[Nullable=False,DefaultValue=,MaxLength=8000,FixedLength=True]' of member 'status' in type 'CodeFirstDatabaseSchema.Users_mast'.
My Code:
User_mast.cs file contains:
[Column(TypeName = binary)]
public byte status { get; set; } // Active | Inactive (1 | 0 ), where I want status column to be created as binary column in sql server.
context.cs file contains:
public class context : DbContext
{
public context()
: base("name=sqlConn")
{
}
public DbSet<Users_mast> Users { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
and finally,
test.cs file contains:
context obj = new context();
public void add()
{
obj.Users.Add(new Users_mast() {user_fname="Agnib", user_lname="Pyne", user_email="a@gmail.com", user_mobile="9830972301", username="agnib", pwd="As1232", created_date=DateTime.Now, status=1 });
obj.SaveChanges();
}
On running, I am getting the above error. I can understand its due to the status field set as byte which is not getting mapped as binary.
Then what should I do to make the column in sql server as binary? Is there any list of mapping between sql server types and .net types specially in case of EF Code-First?
Any help is appreciated. Please help!!!