[英]EF6 many-to-many table with additional date column
我在數據庫優先模式下使用表User
來使用EF6。
我希望用戶能夠通過使用委托與其他用戶共享其個人資料。 為此,我定義了一個具有兩列的表UserDelegation
: IdUser
和IdDelegatedUser
。 到這里為止,一切都按預期進行。
現在,我想添加一列用於在UserDelegation
表中存儲日期。 問題是:我無法在UserDelegation
實體中調用此屬性,因為該實體UserDelegation
不可見。 因此,我不知道在哪里可以找到我的新房產。
我想知道是否有解決此問題的方法或此體系結構是否錯誤?
這是我根據您的描述得到的-您可以嘗試刪除EDMX中的實體,然后嘗試重新生成它。
我對您所說內容的解釋:
DbContext
public List<UserProfile> GetProfiles()
{
using (var ctx = new UserDatabaseEntities())
{
var ret = ctx.UserProfiles.Include("UserDelgations").Select(p => p).ToList();
return ret;
}
}
的SQL
CREATE TABLE [dbo].[UserDelgations] (
[UserProfileId] UNIQUEIDENTIFIER NOT NULL CONSTRAINT FK_UserProfiles_UserProfileId FOREIGN KEY REFERENCES dbo.UserProfiles (Id) ON DELETE CASCADE,
[UserProfileDelgationId] UNIQUEIDENTIFIER NOT NULL,
[AuditDate] DATETIME NOT NULL default(getutcdate()),
) Go
ALTER TABLE [dbo].[UserDelgations] ADD CONSTRAINT PK_UserDelgations PRIMARY KEY ([UserProfileId] ASC, [UserProfileDelgationId] ASC) GO
CREATE TABLE [dbo].[UserProfiles] (
Id uniqueidentifier NOT NULL constraint PK_UserProfiles primary key nonclustered (Id) constraint DF_UserProfiles_Id default(newid()),
UserName NVARCHAR(1024) NOT NULL,
CreatedBy NVARCHAR(256) NOT NULL default(SYSTEM_USER),
CreatedDate DATETIME NOT NULL default(getutcdate()),
) Go
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.