【发布时间】:2012-02-14 03:04:10
【问题描述】:
我在以下场景中遇到了数据库生成问题:
1.cs 映射到 First_Project 表的 First.Entities 命名空间中的项目实体。
namespace First.Entities
{
#region using section
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;
using System.Diagnostics.CodeAnalysis;
#endregion
[Table("First_Project")]
public class Project
{
[Key]
public int Id
{
get;
set;
}
[Required]
[MaxLength(1000)]
public string Name
{
get;
set;
}
}
}
2.cs 映射到 Second_Project 表的 Second.Entities 命名空间中的项目实体。
namespace Second.Entities
{
#region using section
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;
using System.Diagnostics.CodeAnalysis;
#endregion
[Table("Second_Project")]
public class Project
{
[Key]
public int Id
{
get;
set;
}
[Required]
[MaxLength(1000)]
public string Name
{
get;
set;
}
}
}
3.cs DbContext 文件
namespace DataContext
{
#region using section
using System.Collections.Generic;
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Diagnostics.CodeAnalysis;
using First.Entities;
using Second.Entities;
#endregion
public class MyEntities : DbContext
{
public DbSet<First.Entities.Project> FirstProjects { get; set; }
public DbSet<Second.Entities.Project> SecondProjects { get; set; }
}
}
请帮忙。
【问题讨论】:
-
您遇到什么错误?您需要什么帮助?
-
在这种情况下无法创建数据库。错误是:
-
“Second.Entities.Project”类型未映射。使用 Ignore 方法或 NotMappedAttribute 数据注释检查该类型是否被显式排除。验证该类型是否被定义为一个类,不是原始的、嵌套的或泛型的,并且不是从 EntityObject 继承的。
-
如何修复我的场景。我不想重命名项目类别。我想有 2 个项目类,但在不同的命名空间中。
标签: c# entity-framework entity-framework-4.1 code-first