I have created a custom C# (4.0) class to be used in properties of EF (4.1) model classes. The only property of this custom class has Guid as its type. Now, I would be interested to know if I could serialize my custom class into a Guid column on model tables as if it were a primitive type (supported by SQL Server 2008 R2).
Specifically, I do not wish to use plain Guid as property, as the model properties have conceptually distant meaning and functionality from Guid. I won’t be using the Guid as primary key. Rather, I will use it as a foreign key to access another table/collection that has non-primary Guid column/property (and several rows/instances with identical Guid). This may sound far-fetched but it would be very handy design for this specific purpose.
Off the top of my head, I think the following approach might work with EF:
As far as EF is aware, you just have that
Guidproperty, but as far as your model knows when you’re coding, you just have the custom type property.To create the implicit conversions: