I am using EF6 in database-first mode with a table User
.
I want users to be able to share their profiles with other users by using delegation. For this, I defined a table UserDelegation
with 2 columns : IdUser
and IdDelegatedUser
. Until here, everything is working as expected.
Now, I want to add a column for storing dates in the UserDelegation
table. The problem is : I'm not able to call this property in my EF6 entities because the entity UserDelegation
is not visible. Thus, I don't know where to look for my new property Date
I wonder if there is a way to resolve this problem or if this architecture is wrong ?
Here is what i got based on your description - You can try deleting the entity in the EDMX and try regenerating it.
My Interpretation of what you said:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.