简体   繁体   中英

F#: Entity Framework Issue With File Order

Is there a way for two entities with foreign key relations to be represented in class files keeping in mind that F# has to have the files in order?

Say I have a User and the user has books.

type User(books:seq<Book>) :
  mutable _books = books

  member public x.Books
    with get() = _books
    and set bookList = _books  <- bookList


type Books(parentUser:User) : 
  mutable _parentUser = parentUser

  member public x.ParentUser
    with get() = _parentUser
    and set newParentUser = _parentUser <- newParentUser

Now because of how F# works, this won't compile since it's basically a circular reference. User comes before Book therefore it doesn't know what a book is. If I move the book class up, the opposite is true.

Is there a way around the whole "Compile in order" way that F# works or do I need to set up entities and relations in another language?

You'll need to define both types in the same file using type User ... and Books . See the section on Mutually Recursive Types on MSDN .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM