0

我的 OrchardCMS 迁移有问题,以下代码执行迁移失败(因为我创建 ContentItem 是为了说明目的),错误会引发创建内容类型:

       public class Migrations : DataMigrationImpl {
    private readonly IContentManager _contentManager;
    public Migrations(IContentManager contentManager)
    {
        _contentManager = contentManager;
    }

    public int Create() {
        SchemaBuilder.CreateTable("MedioPartRecord", table => table
            .ContentPartRecord()
            .Column<string>("Identificador")
            .Column<string>("Matricula")
            .Column<string>("NumeroSistemaGPS")
            .Column<string>("Observaciones")
            .Column("Matriculacion",DbType.DateTime)
            .Column<int>("IdTipoMedio")
            .Column("InicioTrabajo", DbType.DateTime)
            .Column<int>("Kms"));

        ContentDefinitionManager.AlterTypeDefinition("TipoMedio", type => type
             .Creatable()
             .WithPart("TitlePart")
             .WithPart("CommonPart"));


      ContentDefinitionManager.AlterPartDefinition(typeof(MedioPart).Name, part => part.Attachable());
       ContentDefinitionManager.AlterTypeDefinition("Medio", type => type
            .Creatable()
            .WithPart("CommonPart")
            .WithPart("MedioPart")
            );

        return 1;
    }
    public class MedioPartRecord : ContentPartRecord {
    public virtual string Identificador { get; set; }
    public virtual string Matricula { get; set; }
    public virtual string NumeroSistemaGPS { get; set; }
    public virtual string Observaciones { get; set; }
    public virtual DateTime Matriculacion { get; set; }
    public virtual DateTime InicioTrabajo { get; set; }
    public virtual int IdTipoMedio { get; set; }
    public virtual int Kms { get; set; }


}




public class MedioPart : ContentPart<MedioPartRecord>
{
    public virtual int IdTipoMedio { get { return Record.IdTipoMedio; } set { Record.IdTipoMedio = value; } }
    public virtual string Identificador { get { return Record.Identificador; } set { Record.Identificador = value; } }
    public virtual string Matricula { get { return Record.Matricula; } set { Record.Matricula = value; } }
    public virtual string NumeroSistemaGPS { get { return Record.NumeroSistemaGPS; } set { Record.NumeroSistemaGPS = value; } }
    public virtual string Observaciones { get { return Record.Observaciones; } set { Record.Observaciones = value; } }
    public virtual DateTime Matriculacion { get { return Record.Matriculacion; } set { Record.Matriculacion = value; } }
    public virtual DateTime InicioTrabajo { get { return Record.InicioTrabajo; } set { Record.InicioTrabajo = value; } }
    public virtual int Kms { get { return Record.Kms; } set { Record.Kms = value; } }


}

    public class MedioPartHandler : ContentHandler {
    public MedioPartHandler(IRepository<MedioPartRecord> repository)
    {
        Filters.Add(StorageFilter.For(repository));
    }
}

谢谢

4

1 回答 1

1

问题是我忘记将日期时间设置为可空类型。

于 2013-07-26T14:14:00.130 回答