【发布时间】:2016-08-30 11:56:25
【问题描述】:
我在 SQL 中有一个名为 ViewTest 的视图。
在代码中我有这个模型
[Table("dbo.ViewTest")]
public class ViewTest
{
public int Id { get; set; }
public int EmployeeID { get; set; }
public string PreferredName { get; set; }
public string EmailPrimaryWork { get; set; }
public string GeoCoverage { get; set; }
public string Role { get; set; }
public bool? LeftEmpFlag { get; set; }
}
在配置文件中:
public virtual IDbSet<ViewTest> ViewTests { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new ViewConfiguration());
}
public class ViewConfiguration : EntityTypeConfiguration<ViewTest>
{
public ViewConfiguration()
{
this.HasKey(t => t.Id);
this.ToTable("ViewTest");
}
}
我想有这样一个 ViewTests.Where(....) 的连接,但是当我尝试这样做时,我遇到了错误 数据库中已经有一个名为“ViewTest”的对象。。这意味着实体框架尝试创建新表,我不想要这个。我只想访问这个视图!
【问题讨论】:
标签: asp.net-mvc code-first entity-framework-migrations sql-view