Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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();
}

SQL
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!!!
Posted
Updated 7-May-20 6:04am

if you only need to store 0 or 1 values in the column you can simply use bit datatype in sql server and Boolean data type in .net.
also .net Byte[] will convert as binary in sql server
 
Share this answer
 
Comments
Member 11072126 12-Aug-15 13:08pm    
Thanks a lot man. It worked.
In my case, all columns were set correctly, but Oracle Unmanaged Driver apparently doesn't always load into visual studio quite right.

I could get it to work *sometimes*, but it often failed after restarting my visual studio development machine. I experimented with combinations of rebuilding + reloading T4 templates and Re-compiling files in the solution (MVC5 + EF + AngularJS + Bundled Web optimization).
In the end, this turned out to be a more straight forward solution:

This:
<a href="https://community.oracle.com/thread/2398397">Error 2019: Member Mapping specified is not valid. | Oracle Community</a>[<a href="https://community.oracle.com/thread/2398397" target="_blank" title="New Window">^</a>]

 - (a) Open Visual Studio Help/About Microsoft Visual Studio and click
   OK button to exit the dialog box 
 - OR 
 - (b) Open the to-be-used connection in Server Explorer
 
Share this answer
 
Comments
Richard MacCutchan 7-May-20 12:49pm    
As you can see above this was solved five years ago.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900