【发布时间】:2015-02-20 16:00:04
【问题描述】:
如果此表不存在,则希望在应用程序启动时创建此表。
代码:
public class Database : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
var db = applicationContext.DatabaseContext.Database;
//Cant add this table due to the ENUM
if (!db.TableExist("FormData"))
{
db.CreateTable<FormData>(false);
}
}
}
型号:
[PrimaryKey("Id")]
public class FormData
{
[PrimaryKeyColumn(AutoIncrement = true, IdentitySeed = 1)]
public int Id { get; set; }
[NullSetting(NullSetting = NullSettings.NotNull)]
public FormType Type { get; set; }
[NullSetting(NullSetting = NullSettings.NotNull)]
public string Data { get; set; }
[NullSetting(NullSetting = NullSettings.NotNull)]
public DateTime Date { get; set; }
}
错误信息:
[InvalidOperationException:序列不包含匹配元素] System.Linq.Enumerable.First(IEnumerable
1 source, Func2 谓词)+415 Umbraco.Core.Persistence.SqlSyntax.SqlSyntaxProviderBase1.FormatType(ColumnDefinition column) +1225 Umbraco.Core.Persistence.SqlSyntax.SqlSyntaxProviderBase1.Format(ColumnDefinition 列) +155 Umbraco.Core.Persistence.SqlSyntax.SqlSyntaxProviderBase1.Format(IEnumerable1 列)+144 Umbraco.Core.Persistence.SqlSyntax.SqlSyntaxProviderBase`1.Format(TableDefinition 表) +131 Umbraco.Core.Persistence.PetaPocoExtensions.CreateTable(数据库数据库,布尔覆盖,类型模型类型)+161 Umbraco.Core.Persistence.PetaPocoExtensions.CreateTable(Database db, Boolean overwrite) +121
查看错误我认为不更新核心没有解决方案,但希望你们能提供帮助
【问题讨论】: