[英]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? 有没有办法让两个具有外键关系的实体在类文件中表示,请记住F#必须按顺序存放文件?
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. 现在因为F#的工作方式,这不会编译,因为它基本上是一个循环引用。 User comes before Book therefore it doesn't know what a book is.
用户来到Book之前因此它不知道一本书是什么。 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? 有没有办法解决整个“按顺序编译”的方式F#的工作原理还是我需要用另一种语言设置实体和关系?
You'll need to define both types in the same file using type User ... and Books
. 您需要使用
type User ... and Books
类型在同一文件中定义这两种类型。 See the section on Mutually Recursive Types on MSDN . 请参阅MSDN上的“ 相互递归类型 ”一节。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.