简体   繁体   English

当两个实体都位于不同的SQL Server数据库中时,请首先在实体框架代码中配置多对多关系。

[英]Configuring many-to-many relationship in Entity Framework Code First when both entities reside in different SQL Server Databases.

I'm relatively new to software development and i'm currently finishing up a project that I'm hoping to show at future job interviews. 我对软件开发比较陌生,目前正在完成一个项目,希望在以后的工作面试中展示。 In this project, using code-first I want to set up a many-to-many relationship between an ApplicationUser and a domain Entity and have the resulting associative table persist other information that pertains to this association. 在此项目中,我想使用代码优先功能在ApplicationUser和域Entity之间建立多对多关系,并使生成的关联表保留与该关联有关的其他信息。 The idea is that a user would be able to like many images and an image would be able to have many users like it. 这个想法是,用户将能够喜欢许多图像,而图像将能够使许多用户喜欢它。 The problem that I've come across is that the Identity Database and the domain database are not the same. 我遇到的问题是身份数据库和域数据库不相同。 So my questions are: 所以我的问题是:

1) How would I be able to create the many-to-many association between the ApplicationUsers and the Photos if both Entities are persisted in different SQL Server Databases? 1)如果两个实体都保存在不同的SQL Server数据库中,我将如何在ApplicationUsers和Photos之间创建多对多关联?

2) How could I add a field to store extra information (a bool to account for whether the user liked the image or not) in that resulting associative table? 2)如何在该结果关联表中添加一个字段来存储额外的信息(说明用户是否喜欢该图像的布尔值)?

Thanks in advance for the answers, I'm usually able to find answers on my own but this one seems to be a little off the beaten track. 在此先感谢您提供答案,通常我可以自己找到答案,但是这个答案似乎有些偏离。

Create a ApplicationUser table in the domain database and have your image/user junction table reference that. 在域数据库中创建ApplicationUser表,并让您的图像/用户联结表引用该表。 Every time a user logs into your application, insert/update that user record with the relevant information from your identity database. 每次用户登录到您的应用程序时,请使用身份数据库中的相关信息插入/更新该用户记录。 If your identity database serves only the single application, you can combine the two databases. 如果身份数据库仅服务于单个应用程序,则可以合并两个数据库。

暂无
暂无

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

相关问题 通过具有多对多关系的实体框架代码优先方法为 SQL Server 播种 - Seeding SQL Server by Entity Framework code-first approach with many-to-many relationship Entity Framework 4.1 - Code First:多对多关系 - Entity Framework 4.1 - Code First: many-to-many relationship 实体框架代码首先与现有实体进行多对多关系 - Entity Framework Code First Many to Many Relationship with Existing Entities 定义多对多关系时,实体框架是插入实体 - Entity Framework is Inserting entity when defining a many-to-many relationship 实体框架代码优先多对多不使用 GUID 加载相关实体 - Entity Framework Code First Many-To-Many not loading related entities using GUID 实体框架代码优先:多对多关系; 从用户中删除一些角色 - Entity Framework Code First: Many-to-Many relationship; Remove some Roles from the User 编写第一个实体框架(EF6)的代码,在初始创建后添加多对多关系 - Code first Entity Framework (EF6) Adding Many-to-Many relationship after initial create Code First Entity Framework中的Seed方法未填充多对多关系中的链接表 - The link table in Many-to-many relationship is not populated by the Seed method in Code First Entity Framework 如何首先使用Entity Framework代码创建多对多关系? - How do I create a many-to-many relationship with Entity Framework code first? 实体框架核心代码优先:级联删除多对多关系 - Entity Framework Core Code-First: Cascade delete on a many-to-many relationship
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM