来讨论讨论

堵住并发下的制品超卖思路是接收redis串行管理多少,但又有高产出管理数据的本领

ServiceStack.OrmLite 笔记2

那篇主要介绍 扩展

db.Insert(new Employee { Id = 1, Name = “Employee 1” }); //默承认步

await db.InsertAsync(new Employee { Id = 1, Name = “Employee 1” });
//异步 其余的异步肖似这里的这些示例

db.InsertOnly(new Person { FirstName = “Amy” }, q => q.Insert(p =>
new {p.FirstName}))
// 插入部分字段 前边的参数q.Insert代表要插入的字段 生成sql: INSERT INTO
“Person” (“FirstName”) VALUES (‘Amy’)

var rowId = db.Insert(new Poco { Text = “Text” },
selectIdentity:true);// selectIdentity:true再次回到自拉长的id

此处代码有一些多 全局的插入时过滤 近似的有UpdateFilter
,以为正是插入时对数据开展拦阻,能够发布您的想像,举个例子能够在那处加日志,或许扩充新的字段,交欢做的政工。
public interface IAudit
{
DateTime CreatedDate { get; set; }
DateTime ModifiedDate { get; set; }
string ModifiedBy { get; set; }
}

//表对应的类
public class AuditTableA : IAudit
bwin必赢棋牌,{
public AuditTableA()
{
this.CreatedDate = this.ModifiedDate = DateTime.UtcNow;
}

    [AutoIncrement]
    public int Id { get; set; }
    public DateTime CreatedDate { get; set; }
    public DateTime ModifiedDate { get; set; }
    public string ModifiedBy { get; set; }
}

OrmLiteConfig.InsertFilter = (dbCmd, row) => {
var auditRow = row as IAudit;
if (auditRow != null)
auditRow.CreatedDate = auditRow.ModifiedDate = DateTime.UtcNow;
};
上边是上边方法的新体位,也出自官方网站。对数据举行验证
OrmLiteConfig.InsertFilter = OrmLiteConfig.UpdateFilter = (dbCmd, row)
=> {
var auditRow = row as IAudit;
if (auditRow != null && auditRow.ModifiedBy == null)
throw new ArgumentNullException(“ModifiedBy”);
};

try
{
db.Insert(new AuditTable());
}
catch (ArgumentNullException) {
//throws ArgumentNullException
}

db.Insert(new AuditTable { ModifiedBy = “Me!” }); //succeeds

下边包车型客车代码因为也可能有insert 就也放上吧
在表被创制恐怕去除的时候执行sql语句
[PostCreateTable(“INSERT INTO TableWithSeedData (Name) VALUES (‘Foo’);”

  • “INSERT INTO TableWithSeedData (Name) VALUES (‘Bar’);”)]
    public class TableWithSeedData
    {
    [AutoIncrement]
    public int Id { get; set; }
    public string Name { get; set; }
    }

typeof(TableWithSeedData)
.AddAttributes(new PostCreateTableAttribute(
“INSERT INTO TableWithSeedData (Name) VALUES (‘Foo’);” +
“INSERT INTO TableWithSeedData (Name) VALUES (‘Bar’);”));

前戏和之后,都是能够有和好的游戏的方法
[PreCreateTable(runSqlBeforeTableCreated)][PostCreateTable(runSqlAfterTableCreated)]
[PreDropTable(runSqlBeforeTableDropped)][PostDropTable(runSqlAfterTableDropped)]
public class Table {}

Db.ExecuteSql(“INSERT INTO page_stats (ref_id, fav_count) VALUES
(@refId, @favCount)”, new { refId, favCount }) //直接施行sql语句

Db.ExecuteSqlAsync(“UPDATE page_stats SET view_count = view_count + 1
WHERE id = @id”, new { id })//直接实行sql语句

产品表(product) 

class Product

{

  public int Id{get;set} //自增Id

       public string Name{get;set}//产品名称

       public int Number{get;set}//库存

       public DateTime N提姆e{get;set;}//仓库储存同步时间

       ….

}

仓库储存改造记录表(productNumberRecord)

class productNumberRecord

{

  public int Id{get;set;}

       public int Number{get;set;} //本次消耗仓库储存数量

       public int SurplusNumber{get;set} //这一次消耗后的剩下数量

       public DataTime Time{get;set;} //记录时间

       ….

发表评论

电子邮件地址不会被公开。 必填项已用*标注