繁体   English   中英

添加/插入petapoco与dapper的风格

[英]Add/Insert style of petapoco vs dapper

我为此感到高兴

//用peta poco插入记录

var a = new Article();
a.title="My new article";
a.content="PetaPoco was here";
a.date_created=DateTime.UtcNow;
db.Insert(a);

我对此感到分心

//用dapper插入记录

var a = new Article();
a.title="My new article";
a.content="PetaPoco was here";
a.date_created=DateTime.UtcNow;
string articleQuery= "INSERT INTO Article VALUES (@Title, @Content, @Date)";        
connection.Execute(articleQuery, new { Title = a.Title, Content = a.Content, Date = a.Date });

我是dapper和peta poco的新手。 可能是我没有找到更多的小巧玲珑,但我真的不喜欢我必须插入的方式。 Peta poco似乎非常有意义。

能不能用这种方式做事吗?

如果你喜欢PetaPoco风格更好,那就去吧。 尽管Dapper更有名,但PetaPoco具有相同的性能,具有相同的概念,但它更灵活(IMO)

使用Dapper查看“魔术”CRUD操作的dapper扩展

using (SqlConnection cn = new SqlConnection(_connectionString))
{
    cn.Open();
    Person person = new Person { FirstName = "Foo", LastName = "Bar" };
    int id = cn.Insert(person);
    cn.Close();
}

另请参阅主题以获取更多信息

开发人员因其性能而使用Drapper。 对于许多网站来说,PetaPoco已经足够好了,但是如果你想提取所有服务器'果汁',请使用Drapper。 实际上它是Stackoverflow使用的ORM。 您可以在此处查看所有ORM性能比较

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM