[英]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.