Entity framework maps DB types to .NET types, for instance SQL Server’s BigInt is mapped to .NET’s long.
Is it possible to create a new type and have a store type (such as BigInt or VarChar) mapped to it? If so, how?
FYI, my goal is to change the way the .NET scalar writes its value to the query, and specifically the way its default value is written (I’m trying to use SQL Server’s default keyword to solve problem such as this).
Thanks,
Asaf
Update
Found a post for EF 1 saying it can’t be done. I’m not sure it’s correct for its time, and I’m even less sure it’s relevant for EF 4.
I’m almost sure you can’t create new scalar types even in EF4.0.
What you actually can do is to create a Complex type wrapping underlying scalar type. Complex types are supported by designer in VS2010.
Provide any default value you want and a couple of implicit conversion operators.
So every entity having complex property of
DateTimeWrappertype will be correctly initialized. And you can use syntax like this:MyEntity.MyDateTimeWrapperProp = DateTime.UtcNowwhen creating and modifying entities.But in queries you’ll have to write
MyEntities.Where(ent => ent.MyDateTimeWrapperProp.Value == ...).