I have an class
public class Foo
{
public int UserId { get; set; }
}
and I’m using the code first fluent mapping to map this to the database.
Property(i => i.UserId)
.HasColumnName("userno");
the only problem is that userno is actually a char(10) in the database. How do I go about casting or converting this type? as I currently get this error.
The ‘UserId’ property on ‘Foo’ could not be set to a ‘String’ value.
You must set this property to a non-null value of type ‘Int32’.
Thanks
Entity framework doesn’t have any support for type conversion in mapping so the only valid mapped property in your scenario is:
If you want
intproperty as well you must do:And add this to your mapping:
You can play with accessibility of
UserIdproperty but be aware that accessibility also affects if your mapping actually sees the property. If it doesn’t you will not haveUserIdmapped at all.