从数据库生成模型时,实体框架 4 隐藏底层解析器表
从头开始创建实体框架模型时,可以在模型中指定多对多关系。
例如 Entity1 * ----- * Entity2
当由此生成数据库时,会在两个实体之间自动创建解析器表,该表隐藏在代码模型中,允许通过属性直接访问每个实体。
例如 Entity1 ----* ResolverEntity *----- Entity2
我的问题是,当从包含解析器表的现有数据库生成模型时,是否可以创建相同的效果,以便解析器表不会出现在生成的对象模型?
当我尝试这样做时,实体框架似乎在模型中为解析器表创建实体,而没有明显的方法将它们隐藏在对象模型中。
谢谢。
When creating an entity framework model from scratch it is possible to specify a Many to Many relationship in the model.
e.g Entity1 * ----- * Entity2
When a database is then generated from this, a resolver table is then created automatically between the two entities, this is hidden in the code model, allowing direct access to each of the entities via properties.
e.g. Entity1 ----* ResolverEntity *----- Entity2
My question is, when a model is generated from an existing database, which contains resolver tables, is it possible to create the same effect so the resolver tables do not appear in the generated object model?
When I have attempted this, the entity framework appears to create entities in the model for the resolver tables with no obvious way of hiding them in the object model.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,前提是您所说的“解析器表”仅包含两列,即实体 1 和实体 2 的 FK,并且这两列形成复合 PK。在这种情况下,EF GUI 设计器将识别该模式并生成多对多关系。如果您的数据库架构不符合这些约束,您必须手动编辑 EDMX。
Yes, provided that what you're calling the "resolver table" contains only two columns, FKs to Entity1 and Entity2, and that those two columns form a compound PK. In this case, the EF GUI designer will recognize the pattern and generate a many to many relationship. If your DB schema doesn't fit these constraints, you'd have to edit the EDMX by hand.