读书人

Entity Framework Power Tools 生成投

发布时间: 2013-03-21 10:08:17 作者: rapoo

Entity Framework Power Tools 生成映射结果的一个bug,大家看看能否解决
下面是用Entity Framework Power Tools 成生的代码

public partial class Feature
{
public int FeatureID { get; set; }
public string FeatureName { get; set; }
}


public class FeatureMap : EntityTypeConfiguration<Feature>
{
public FeatureMap()
{
// Primary Key
this.HasKey(t => t.FeatureID);

// Properties
this.Property(t => t.FeatureName)
.IsRequired()
.HasMaxLength(50);

// Table & Column Mappings
this.ToTable("Feature");
this.Property(t => t.FeatureID).HasColumnName("FeatureID");
this.Property(t => t.FeatureName).HasColumnName("Feature");

}
}



大家看到this.Property(t => t.FeatureName).HasColumnName("Feature"); 这一行了没?

我数据库中有个表名叫Feature,这张表里有个字段也叫Feature,结果在Entity Framework中运行时报错为
Feature: Name: Name 'Feature' cannot be used in type 'CodeFirstDatabaseSchema.Feature'. Member names cannot be the same as their enclosing type.

请问有没有什么解决办法?数据库字段名是不可能改了!因为多套系统已经在使用了. Entity?Framework
[解决办法]
如果前面加个表名行吗?
this.Property(t => t.FeatureName).HasColumnName("Feature.Feature");

读书人网 >C#

热点推荐