efcore / EFCore.FSharp

Adds F# design-time support to EF Core
MIT License
234 stars 26 forks source link

Example property for `DbSet` does not work #88

Closed rstm-sf closed 3 years ago

rstm-sf commented 3 years ago

Description

Example property for DbSet does not work. This bug?

member __.Blogs : DbSet<Blog> = Unchecked.defaultof<DbSet<Blog>>

https://github.com/efcore/EFCore.FSharp/blob/master/GETTING_STARTED.md#update-the-model

In my option

member x.Products : DbSet<Product> = Unchecked.defaultof<DbSet<Product>>

image

But work with

[<DefaultValue>] val mutable products : DbSet<Product>
member x.Products with get() = x.products and set v = x.products <- v

image

Other information

simon-reynolds commented 3 years ago

Hi @rstm-sf

Thank you for letting me know about this, I'll have to update that documentation

If you instead define your properties like this, it should work. Turns out that reflection setters in EF don't play nice with Unchecked.defaultof<'a>

[<DefaultValue>]
val mutable private _blogs : DbSet<Blog>
member this.Blogs with get() = this._blogs and set v = this._blogs <- v
rstm-sf commented 3 years ago

Ok, thanks!