C# 实体框架电动工具Beta 3列名无效
我一直在一个项目中使用ADO.NET实体数据模型来测试我一直在开发的安全/授权方法。我得到了我想要的一切工作,我需要模仿另一个生产项目的行为 另一个产品是使用Entity Framework Power Tools Beta 3生成类/实体和映射类。到目前为止,它只有模型和映射 我有一个Users表、Roles表和UsersInRoles表(等等) 角色和UsersInRoles之间存在1-many关系,但用户和UsersInRoles之间存在1-1关系 我想我的db关系是正确的。ADO模型似乎这样认为:) 但是当我在使用Power Tools生成的类时,在我的C代码中调用db.Users时: {“执行命令定义时出错。有关详细信息,请参阅内部异常。”} {“无效的列名'Role_RoleId'。” 当我执行EF命令-View Entity数据模型DDL SQL时,我看到一个名为Role_RoleID的列,这是不正确的…对吗 数据库表Users中没有Role_RoleId。此外,在模型或映射文件中不会生成UsersInRoles如何修复此问题?我不知所措。C# 实体框架电动工具Beta 3列名无效,c#,asp.net-mvc-4,visual-studio-2012,entity-framework-5,C#,Asp.net Mvc 4,Visual Studio 2012,Entity Framework 5,我一直在一个项目中使用ADO.NET实体数据模型来测试我一直在开发的安全/授权方法。我得到了我想要的一切工作,我需要模仿另一个生产项目的行为 另一个产品是使用Entity Framework Power Tools Beta 3生成类/实体和映射类。到目前为止,它只有模型和映射 我有一个Users表、Roles表和UsersInRoles表(等等) 角色和UsersInRoles之间存在1-many关系,但用户和UsersInRoles之间存在1-1关系 我想我的db关系是正确的。ADO模型似乎
[...]
create table [Auth].[Users] (
[UserId] [uniqueidentifier] not null,
[UserName] [nvarchar](100) not null,
[FullUserName] [nvarchar](100) not null,
[Password] [nvarchar](150) not null,
[PasswordSalt] [nvarchar](50) not null,
[IsEnabled] [bit] not null,
[IsLockedOut] [bit] not null,
[Email] [nvarchar](150) not null,
[DateCreated] [datetime] not null,
[LastModified] [datetime] not null,
[Role_RoleId] [uniqueidentifier] null,
primary key ([UserId])
);
alter table [Auth].[Users] add constraint [User_Role] foreign key ([Role_RoleId]) references [Auth].[Roles]([RoleId]);
[...]
SQL Server表
CREATE TABLE [Auth].[Users](
[UserId] [uniqueidentifier] NOT NULL,
[UserName] [nvarchar](100) NOT NULL,
[FullUserName] [nvarchar](100) NOT NULL,
[Password] [nvarchar](150) NOT NULL,
[PasswordSalt] [nvarchar](50) NOT NULL,
[IsEnabled] [bit] NOT NULL,
[IsLockedOut] [bit] NOT NULL,
[Email] [nvarchar](150) NOT NULL,
[DateCreated] [datetime2](7) NOT NULL,
[LastModified] [datetime2](7) NOT NULL,
CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED
(
[UserId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE TABLE [Auth].[Roles](
[RoleId] [uniqueidentifier] NOT NULL,
[RoleName] [nvarchar](100) NOT NULL,
[Description] [nvarchar](250) NULL,
CONSTRAINT [PK_Roles] PRIMARY KEY CLUSTERED
(
[RoleId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE TABLE [Auth].[UsersInRoles](
[UserId] [uniqueidentifier] NOT NULL,
[RoleId] [uniqueidentifier] NOT NULL,
CONSTRAINT [PK_UsersInRoles] PRIMARY KEY CLUSTERED
(
[UserId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [Auth].[UsersInRoles] WITH CHECK ADD CONSTRAINT [FK_UsersInRoles_Roles] FOREIGN KEY([RoleId])
REFERENCES [Auth].[Roles] ([RoleId])
ON UPDATE CASCADE
ON DELETE SET DEFAULT
GO
ALTER TABLE [Auth].[UsersInRoles] CHECK CONSTRAINT [FK_UsersInRoles_Roles]
GO
ALTER TABLE [Auth].[UsersInRoles] WITH CHECK ADD CONSTRAINT [FK_UsersInRoles_Users] FOREIGN KEY([UserId])
REFERENCES [Auth].[Users] ([UserId])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [Auth].[UsersInRoles] CHECK CONSTRAINT [FK_UsersInRoles_Users]
GO
ALTER TABLE [Auth].[UsersInRoles] ADD CONSTRAINT [DF_UsersInRoles_RoleId] DEFAULT ('8B24673F-A4FB-4031-9185-8CCBD96CBE4D') FOR [RoleId]
GO
CS文件
public partial class User
{
public int UserId { get; set; }
public string UserName { get; set; }
public string FullUserName { get; set; }
public string Password { get; set; }
public string PasswordSalt { get; set; }
public bool IsEnabled { get; set; }
public bool IsLockedOut { get; set; }
public string Email { get; set; }
public System.DateTime DateCreated { get; set; }
public System.DateTime LastModified { get; set; }
public virtual Role Role { get; set; }
}
public partial class Role
{
public Role()
{
this.RoleSecurables = new List<RoleSecurable>();
this.Users = new List<User>();
}
public int RoleId { get; set; }
public string RoleName { get; set; }
public string Description { get; set; }
public virtual ICollection<RoleSecurable> RoleSecurables { get; set; }
public virtual ICollection<User> Users { get; set; }
}
public UserMap()
{
// Primary Key
this.HasKey(t => t.UserId);
// Properties
this.Property(t => t.UserName)
.IsRequired()
.HasMaxLength(100);
this.Property(t => t.FullUserName)
.IsRequired()
.HasMaxLength(100);
this.Property(t => t.Password)
.IsRequired()
.HasMaxLength(150);
this.Property(t => t.PasswordSalt)
.IsRequired()
.HasMaxLength(50);
this.Property(t => t.Email)
.IsRequired()
.HasMaxLength(150);
// Table & Column Mappings
this.ToTable("Users", "Auth");
this.Property(t => t.UserId).HasColumnName("UserId");
this.Property(t => t.UserName).HasColumnName("UserName");
this.Property(t => t.FullUserName).HasColumnName("FullUserName");
this.Property(t => t.Password).HasColumnName("Password");
this.Property(t => t.PasswordSalt).HasColumnName("PasswordSalt");
this.Property(t => t.IsEnabled).HasColumnName("IsEnabled");
this.Property(t => t.IsLockedOut).HasColumnName("IsLockedOut");
this.Property(t => t.Email).HasColumnName("Email");
this.Property(t => t.DateCreated).HasColumnName("DateCreated");
this.Property(t => t.LastModified).HasColumnName("LastModified");
}
public RoleMap()
{
// Primary Key
this.HasKey(t => t.RoleId);
// Properties
this.Property(t => t.RoleName)
.IsRequired()
.HasMaxLength(100);
this.Property(t => t.Description)
.HasMaxLength(250);
// Table & Column Mappings
this.ToTable("Roles", "Auth");
this.Property(t => t.RoleId).HasColumnName("RoleId");
this.Property(t => t.RoleName).HasColumnName("RoleName");
this.Property(t => t.Description).HasColumnName("Description");
}
公共部分类用户
{
public int UserId{get;set;}
公共字符串用户名{get;set;}
公共字符串FullUserName{get;set;}
公共字符串密码{get;set;}
公共字符串密码salt{get;set;}
公共布尔值已启用{get;set;}
公共bool IsLockedOut{get;set;}
公共字符串电子邮件{get;set;}
public System.DateTime DateCreated{get;set;}
public System.DateTime LastModified{get;set;}
公共虚拟角色{get;set;}
}
公共部分类角色
{
公共角色()
{
this.RoleSecurables=新列表();
this.Users=新列表();
}
public int RoleId{get;set;}
公共字符串RoleName{get;set;}
公共字符串说明{get;set;}
公共虚拟ICollection角色可管理{get;set;}
公共虚拟ICollection用户{get;set;}
}
公共用户映射()
{
//主键
this.HasKey(t=>t.UserId);
//性质
this.Property(t=>t.UserName)
.IsRequired()
.HasMaxLength(100);
this.Property(t=>t.FullUserName)
.IsRequired()
.HasMaxLength(100);
this.Property(t=>t.Password)
.IsRequired()
.HasMaxLength(150);
this.Property(t=>t.PasswordSalt)
.IsRequired()
.HasMaxLength(50);
this.Property(t=>t.Email)
.IsRequired()
.HasMaxLength(150);
//表和列映射
此.ToTable(“用户”、“身份验证”);
this.Property(t=>t.UserId).HasColumnName(“UserId”);
this.Property(t=>t.UserName).HasColumnName(“用户名”);
this.Property(t=>t.FullUserName).HasColumnName(“FullUserName”);
this.Property(t=>t.Password).HasColumnName(“密码”);
this.Property(t=>t.PasswordSalt).HasColumnName(“PasswordSalt”);
this.Property(t=>t.IsEnabled).HasColumnName(“IsEnabled”);
this.Property(t=>t.IsLockedOut).HasColumnName(“IsLockedOut”);
this.Property(t=>t.Email).HasColumnName(“Email”);
this.Property(t=>t.DateCreated).HasColumnName(“DateCreated”);
this.Property(t=>t.LastModified).HasColumnName(“LastModified”);
}
公共角色映射()
{
//主键
this.HasKey(t=>t.RoleId);
//性质
this.Property(t=>t.RoleName)
.IsRequired()
.HasMaxLength(100);
this.Property(t=>t.Description)
.HasMaxLength(250);
//表和列映射
此.ToTable(“角色”、“授权”);
this.Property(t=>t.RoleId).HasColumnName(“RoleId”);
this.Property(t=>t.RoleName).HasColumnName(“RoleName”);
this.Property(t=>t.Description).HasColumnName(“Description”);
}