Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: any practical differences between 2 types of declarations in DbContext? #73

Closed
zelenij opened this issue Apr 1, 2021 · 4 comments · Fixed by #78
Closed

Question: any practical differences between 2 types of declarations in DbContext? #73

zelenij opened this issue Apr 1, 2021 · 4 comments · Fixed by #78
Labels

Comments

@zelenij
Copy link

zelenij commented Apr 1, 2021

Adding new types to DbContext, your intro suggests this type of syntax

    [<DefaultValue>] val mutable countries : DbSet<Country>
    member __.Countries with get() = __.countries and set v = __.countries <- v

Wouldn't it be the same to use this syntax from practical point of view?

    member val Countries: DbSet<Country> = null with get, set

As far as migrations generation, both seem to work fine...

@simon-reynolds
Copy link
Collaborator

Doesn't seem to make a difference but a plain member val is definitely more succinct
Thank you for this, I'll update the docs and scaffolding generation to switch to a plain member val

This was referenced Apr 1, 2021
@GunnerGuyven
Copy link

When I take this approach, the entity members of DBContext remain null. The longer definition works as expected. Am I missing some step?

type MyDataContext() =
    inherit DbContext()

    member val MyExampleTable: DbSet<MyTableType> = null with get,set

    [<DefaultValue>]
    val mutable private myExampleTable2: DbSet<MyTableType2>

    member __.MyExampleTable2
        with get () = __.myExampleTable2
        and set v = __.myExampleTable2 <- v

use db = new MyDataContext()
db.MyExampleTable2.First() |> ignore    // works
db.MyExampleTable.First() |> ignore      // null exception

@simon-reynolds
Copy link
Collaborator

No, it does seem that this approach does result in the members remaining null at runtime
I'll revert these changes in the documentation

@simon-reynolds simon-reynolds mentioned this issue Apr 6, 2021
6 tasks
@zelenij
Copy link
Author

zelenij commented Apr 7, 2021

Looks like this has been raised in the past: fsharp/fslang-suggestions#103

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

3 participants