How to create a virtual record field for Entity Framework lazy loading

I am trying to define some models that I use in Entity Framework 6. I would like to use F # entries. If I put [<CLIMutable>] over the record definition and use ICollection<'a> for, well, collections. EF works great.

I can store and retrieve records. However, for EF for lazy loading, I need to make a record field containing a virtual collection. I can make a property item virtual by making it abstract and providing a default value. Entries are not classes. Is it possible to make the recording field virtual?

If I try to enlarge a record with an abstract element, I get this error this declaration element is not permitted in an augmentation

+5
source share
1 answer

As far as I know, you cannot define a virtual participant in a record - this makes sense because you also cannot inherit a record, so why do you need virtual members.

But I understand why this is necessary for the Entity Framework. It might make sense to have something like the CliVirtual attribute, akin to CliMutable (especially if this happens often). Feel free to suggest this on the F # uservoice page !

So, I think your best option is to use a regular class with virtual automatically implemented properties (which looks much uglier):

 type A() = abstract member Id: int with get, set default val Id = 123 with get, set 

Or maybe see if some other SQL provider for F # can do the same thing more beautifully!

+5
source

Source: https://habr.com/ru/post/1206329/


All Articles