I'm trying to define some models that I use in Entity Framework 6. I would like to use F# records. If I put [<CLIMutable>]
above the record definition and use ICollection<'a>
for, well, the collections. EF works fine.
I can store and retrieve the records. However for EF to do lazy loading I need to make the record field containing the collection virtual. I can make a property member virtual by making it abstract and providing a default. Records are not classes. Is it possible to make a record field virtual?
If I try to augment the record with an abstract member I get this error this declaration element is not permitted in an augmentation
As far as I know, you cannot define a virtual member in a record - this makes sense, because you also cannot inherit from a record, so why would you need virtual members.
But I can see why this would be needed for Entity Framework. Perhaps it would make sense to have something like CliVirtual
attribute, akin to CliMutable
(especially if this happens often). Feel free to suggest this at the F# uservoice page!
So, I guess your best option is to use ordinary class with virtual auto-implemented properties (which looks significantly uglier):
type A() =
abstract member Id: int with get, set
default val Id = 123 with get, set
Or perhaps see if some of the other SQL type providers for F# let you do the same thing more nicely!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With