0

我不明白,我的 model.edmx 有两个表:

在此处输入图像描述

然后我有我的 3 张桌子:

CREATE TABLE [Group].[RecommendedUserGroups]
(
 [Groups_GroupId] INT NOT NULL,
 [RecommendedUsers_RecommendedUserId] int NOT NULL,
 CONSTRAINT [PK_GroupRecommendedUser] PRIMARY KEY CLUSTERED ([Groups_GroupId] ASC, [RecommendedUsers_RecommendedUserId] ASC),
 CONSTRAINT [FK_RecommendedUsers_RecommendedUserGroups] FOREIGN KEY ([RecommendedUsers_RecommendedUserId]) REFERENCES [Zinc].[RecommendedUsers] ([RecommendedUserId]),
 CONSTRAINT [FK_Groups_RecommendedUserGroups] FOREIGN KEY ([Groups_GroupId]) REFERENCES [Group].[Groups] ([GroupId])
 )

CREATE TABLE [Group].[Groups]
(
 [GroupId] INT NOT NULL IDENTITY(1, 1), 
 [Customers_CustomerId] INT NOT NULL,
 [Name] NVARCHAR(128) NOT NULL, 
 [IsArchived] BIT NOT NULL,
 [SmallImageUrl]        NVARCHAR (256) NULL,
 [MediumImageUrl]       NVARCHAR (256) NULL,
 [LargeImageUrl]        NVARCHAR (256) NULL,
 [AllowFiltering] BIT NOT NULL DEFAULT 0, 
  [IsSegment] BIT NOT NULL CONSTRAINT DF_Groups_IsSegment DEFAULT 0,
  CONSTRAINT [PK_Groups] PRIMARY KEY CLUSTERED ([GroupId] ASC), 
  CONSTRAINT [FK_Groups_Customers] FOREIGN KEY ([Customers_CustomerId]) REFERENCES [Zinc].[Customers] ([CustomerId]),      
 )

CREATE TABLE [Zinc].[RecommendedUsers]
(
 [RecommendedUserId]                 INT IDENTITY(1,1) NOT NULL,             
 [Firstname]                         NVARCHAR (50)    NOT NULL,
 [Surname]                           NVARCHAR (50)    NOT NULL,
 [Email]                             NVARCHAR (256)   NOT NULL,
 [Department]                        NVARCHAR (256)   NULL,
 [JobTitle]                          NVARCHAR (256)   NULL, 
 [DateAndTimeProcessed]              DATETIME         NULL,
 [Users_UserId]                      INT              NOT NULL, 
 [DateAndTimeRecommended]            DATETIME         NOT NULL,
 [AssignedUserId]                    INT              NULL,  
 CONSTRAINT [PK_RecommendedUsers] PRIMARY KEY CLUSTERED ([RecommendedUserId] ASC),
)

然后是我的实体:

namespace Zinc.Entities
{
 public class RecommendedUser
 {
  #region Properties

 public virtual int RecommendedUserId { get; set; }
 public virtual string Firstname { get; set; }
 public virtual string Surname { get; set; }
 public virtual string Email { get; set; }
 public virtual string Department { get; set; }
 public virtual string JobTitle { get; set; }
 public virtual DateTime? DateAndTimeProcessed { get; set; }
 public virtual int Users_UserId { get; set; }
 public virtual DateTime? DateAndTimeRecommended { get; set; }
 public virtual int AssignedUserId { get; set; }
 public virtual ICollection<Group.Group> Groups { get; set; }

#endregion

 }
}

namespace Zinc.Entities.Group

{ 公共类组 { #region 属性

public virtual int GroupId { get; set; }
public virtual string Name { get; set; }
public virtual bool IsArchived { get; set; }
public virtual bool IsSegment { get; set; }
public virtual bool AllowFiltering { get; set; }

public virtual string SmallImageUrl { get; set; }
public virtual string MediumImageUrl { get; set; }
public virtual string LargeImageUrl { get; set; }

public virtual Entities.Customer Customer { get; set; }

#endregion

#region ICollections

 //i am only concerned with recommended user so will just put this collection here


  private ICollection<RecommendedUser> _groupRecommendedUsers;
public virtual ICollection<RecommendedUser> RecommendedUsers
{
  get
  {
    if (_groupRecommendedUsers == null)
      _groupRecommendedUsers = new List<RecommendedUser>();

    return _groupRecommendedUsers;
  }
  set
  {
    _groupRecommendedUsers = value;
  }
}

所以当我保存带有推荐用户详细信息的组时,它会写入我的推荐用户表但不会更新我的推荐用户组表?

有人可以帮忙吗?我用mvc3

4

1 回答 1

1

RecommendedUserGroups 表的主键应该是表中的两个字段。

表的定义方式每个组只能有一个成员。

于 2013-03-27T19:32:19.560 回答