【发布时间】:2018-04-19 07:28:51
【问题描述】:
大约 4 年前,我asked this question。然后我决定当时不使用 OrmLite,但我现在又回来了。
这一次,我想知道我在哪里添加添加运行时属性的代码?我尝试如下,但运行时属性没有出现。
我显然错过了一些东西,但是什么?
public ActorNotificationDbHandler()
{
DbAccount dbAccount = DBAccounts[0];
SetTableMeta();
_dbFactory = new OrmLiteConnectionFactory($"Uid={dbAccount.Username};Password={dbAccount.Password};Server={dbAccount.Address};Port={dbAccount.Port};Database={dbAccount.Database}", MySqlDialect.Provider);
_db = _dbFactory.Open();
if (_db.CreateTableIfNotExists<ActorNotification>())
{
_db.Insert(new ActorNotification { CreatedTime = DateTime.Now, ToActor = 123, Status = ActorNotification.ActorNotificationStatuses.Created });
_db.Insert(new ActorNotificationMessage { ActorNotificationId = 1, MessageState = ActorNotificationMessage.MessageStates.Created });
}
var result = _db.SingleById<ActorNotification>(1);
result.PrintDump(); //= {Id: 1, Name:Seed Data}
}
private void SetTableMeta()
{
typeof(ActorNotification).GetProperty("Id").AddAttributes(new IndexAttribute { Unique = true }, new AutoIncrementAttribute());
typeof(ActorNotification).GetProperty("ToActor").AddAttributes(new IndexAttribute { Unique = false });
typeof(ActorNotification).GetProperty("CoreObjectId1").AddAttributes(new IndexAttribute { Unique = false });
typeof(ActorNotification).GetProperty("CoreObjectId2").AddAttributes(new IndexAttribute { Unique = false });
typeof(ActorNotification).GetProperty("Status").AddAttributes(new IndexAttribute { Unique = false });
typeof(ActorNotification).GetProperty("CreatedTime").AddAttributes(new IndexAttribute { Unique = false });
typeof(ActorNotificationMessage).GetProperty("Id").AddAttributes(new IndexAttribute { Unique = true }, new AutoIncrementAttribute());
typeof(ActorNotificationMessage).GetProperty("ActorNotificationId").AddAttributes(new IndexAttribute { Unique = false });
typeof(ActorNotificationMessage).GetProperty("FrontEndServerHandler").AddAttributes(new IndexAttribute { Unique = false });
typeof(ActorNotificationMessage).GetProperty("TimeCreated").AddAttributes(new IndexAttribute { Unique = false });
typeof(ActorNotificationMessage).GetProperty("TimeStatusChanged").AddAttributes(new IndexAttribute { Unique = false });
typeof(ActorNotificationMessage).GetProperty("MessageState").AddAttributes(new IndexAttribute { Unique = false });
}
【问题讨论】:
标签: c# servicestack ormlite-servicestack