简体   繁体   English

实体框架一对多,多对多关系

[英]Entity Framework One to Many, Many to Many relationship

I'm building an api using asp.net web api for an application that needs to track all the activities performed by users. 我正在使用ASP.NET Web API为需要跟踪用户执行的所有活动的应用程序构建API。 So in every table I need to have createdUser and updatedUser field with their dates. 因此,在每个表中,我都需要带有日期的createdUser和UpdatedUser字段。 But I faced some challenges on how to go about. 但是我在如何去做方面面临一些挑战。

Here are my concerns: 这是我的担忧:

  1. How can I have that in the User table itself? 我该如何在User表本身中使用它? Which type of relationship do I need for that? 我需要哪种类型的关系?

  2. I have a privilege table than can be created by required users. 我有一个特权表,不能由所需用户创建。 What type of relationship can I have between the Privilege and the User table? 特权和用户表之间可以建立什么类型的关系?

I'm new to Entity Framework so I need some guides. 我是实体框架的新手,所以我需要一些指南。 Please can anyone be very kind to provide some help. 请任何人能为您提供帮助。 Thank you 谢谢

  1. I don't think u wil need to have that logic in the user table itself. 我认为您不需要在用户表本身中包含该逻辑。 U can add extra colomn's to each table with CreUser,CreDate, LModUser, LModDate. U可以使用CreUser,CreDate,LModUser,LModDate向每个表添加额外的列。 Or U can create an extra table like Entity_ID, Record_ID, User_ID, ModDate, IsCreated. 或者,U可以创建一个额外的表,例如Entity_ID,Record_ID,User_ID,ModDate,IsCreated。 (or with other logic) (或其他逻辑)

  2. search for many to many relations on google. 在Google上搜索多对多关系。 or: 要么:

How to create a many-to-many mapping in Entity Framework? 如何在实体框架中创建多对多映射?

this is a nice tutorial for all kind of relationships in EF for core http://www.learnentityframeworkcore.com/configuration/one-to-many-relationship-configuration 对于核心http://www.learnentityframeworkcore.com/configuration/one-to-many-relationship-configuration,这是一个很好的教程,适用于EF中的各种关系

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM