Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net EF5中的可插拔约定?_.net_Entity Framework_Entity Framework 5 - Fatal编程技术网

.net EF5中的可插拔约定?

.net EF5中的可插拔约定?,.net,entity-framework,entity-framework-5,.net,Entity Framework,Entity Framework 5,可插拔约定是否从EF5版本中删除,我在预发行版中看到过?正在寻找强制ef代码按约定使用datetime2的方法,因此不需要显式映射每个实体的每一列。最终创建了EntityTypeConfiguration的派生类 public class CustomEntityTypeConfiguration<T> : EntityTypeConfiguration<T> where T : EntityBase { public TEntityTypeConfigurati

可插拔约定是否从EF5版本中删除,我在预发行版中看到过?正在寻找强制ef代码按约定使用datetime2的方法,因此不需要显式映射每个实体的每一列。

最终创建了EntityTypeConfiguration的派生类

public class CustomEntityTypeConfiguration<T> : EntityTypeConfiguration<T> where T : EntityBase
{
    public TEntityTypeConfiguration()
    {
        this.Property(t => t.CreatedDate).HasColumnType("datetime2");
    }
}
公共类CustomEntityTypeConfiguration:EntityTypeConfiguration其中T:EntityBase
{
公共TEntityTypeConfiguration()
{
this.Property(t=>t.CreatedDate).HasColumnType(“datetime2”);
}
}

然后,每个实体配置都继承自此,而不是EntityTypeConfiguration。

遇到了类似的问题。我有一个通用存储库,它有一个与您类似的BaseEntity

public class CustomEntityTypeConfiguration<T> : EntityTypeConfiguration<T> where T : EntityBase
{
    public TEntityTypeConfiguration()
    {
        this.Property(t => t.CreatedDate).HasColumnType("datetime2");
    }
}
public abstract class BaseEntity
{
    public int Id { get; set; }
    public DateTime Created { get; set; }
    public DateTime Updated { get; set; } 
}
然后,每个实体都从基础派生

public class MyEntity: BaseEntity
{
    public string Name{ get; set; }
    public int prop1 { get; set; }
    public int prop2 { get; set; }
}
最后,我使用列属性设置BaseEntity的创建和更新属性,如下所示:

public abstract class BaseEntity
{
    [Key, Column(Order = 0)]
    public int Id { get; set; }
    [Column(TypeName = "datetime2")]
    public DateTime Created { get; set; }
    [Column(TypeName = "datetime2")]
    public DateTime Updated { get; set; } 
}
我看了你的解决方案(http://dreadjr.blogspot.com/2012/09/entity-framework-5-code-first-datetime2.html)它看起来也不错,但它要求每个实体都有一个特定的配置类。不管怎样,我想我会和你分享这个