简体   繁体   English

使用实体框架核心2在不同的受限上下文中存储对多个对象的引用

[英]Storing a Reference to multiple objects in a different bounded context using entity framework core 2

I am trying design driven domain and am using entity framework core. 我正在尝试设计驱动领域,并正在使用实体框架核心。 From my understanding of design driven domain I should never reference objects in another bounded context, I can only reference their identifiers. 从对设计驱动域的理解中,我永远不要在另一个有界上下文中引用对象,而只能引用它们的标识符。

I have a class A in bounded context A which references many objects of type B in bounded context B like below were A should only store a reference to ids of the B objects. 我在有界上下文A中有一个类A,它在有界上下文B中引用了许多类型B的对象,如下所示:A应该只存储对B对象ID的引用。

public class A
{
    public int Id { get; private set; }
    public List<int> bIds { get; private set; }
    public int Name { get; private set; }
}

public class B
{
    public int Id { get; private set; }
    public int Name { get; private set; }
}

How do I describe that relationship configuration in the Fluent API? 如何在Fluent API中描述该关系配置? If I don't add any configuration then I get the error The property "'A.bIds' is of type 'List' which is not supported by current database provider. ". 如果不添加任何配置,则会收到错误消息:“'A.bIds'属性为'List'类型,当前数据库提供程序不支持该属性。”。

Thanks 谢谢

The important point is that these two are separate from each other Bounded Context(BC). 重要的一点是,这两者是相互独立的。 If you want to use class B in Bounded Context(BC) A and in the aggregate where the class A is located, class B should be in this ValueObject`s role. 如果要在绑定上下文(BC)A中使用类B,并且要在类A所在的集合中使用类B,则类B应该扮演ValueObject的角色。 And so if you want to communicate between two Bounded Context(BC), you can use Domain Events. 因此,如果要在两个边界上下文(BC)之间进行通信,则可以使用域事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 实体框架(核心),多次引用同一张表但对象不同 - Entity Framework (Core), multiple refrences to the same table but different objects Entity Framework 6 Core - 多列引用 - Entity Framework 6 Core - Reference by multiple columns 实体框架:使用多个自定义历史上下文 - Entity Framework: Using Multiple Custom History Context 在字典中存储实体框架对象 - Storing Entity Framework Objects in Dictionary 具有实体框架的有界上下文和通用存储库,以及具有简单注入器IoC的连线 - Bounded Context and Generic Repository with Entity Framework and wiring with Simple injector IoC 模拟实体框架核心上下文 - Mocking Entity Framework Core context 在不跨越多个上下文对象的情况下,Entity Framework 4中的TransactionScope是否有用途? - Are there uses for TransactionScope in Entity Framework 4 in situations that do not span multiple context objects? Entity Framework Core 使用多个 DbContext - Entity Framework Core Using multiple DbContexts 使用Entity Framework Core获取多个表 - Get multiple tables using Entity Framework Core 实体框架Core 2中相同属性的跨域对象的行为不同 - Different behavior across domain objects for same properties in Entity Framework Core 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM