0

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?

Programmin Tool
  • 6,507
  • 11
  • 50
  • 68
  • 1
    Does http://stackoverflow.com/questions/1378575/f-forward-type-declarations answer your question? –  Dec 12 '11 at 23:01

1 Answers1

2

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.

Daniel
  • 47,404
  • 11
  • 101
  • 179