简体   繁体   English

添加/插入petapoco与dapper的风格

[英]Add/Insert style of petapoco vs dapper

I am delighted by this: 我为此感到高兴

// Insert a record with peta poco //用peta poco插入记录

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

I am distracted by this: 我对此感到分心

// Insert a record with dapper //用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 });

I am new to dapper and peta poco. 我是dapper和peta poco的新手。 It might be that there is more in dapper that I have not found but I really do not like the way I have to do an insert. 可能是我没有找到更多的小巧玲珑,但我真的不喜欢我必须插入的方式。 Peta poco seems to do it very ormish. Peta poco似乎非常有意义。

Can dapper do this somehow too? 能不能用这种方式做事吗?

If you like the PetaPoco style the better, just go for it. 如果你喜欢PetaPoco风格更好,那就去吧。 Although Dapper is more famous, PetaPoco has the same performance, has the same concepts but it's a bit more flexible (IMO) 尽管Dapper更有名,但PetaPoco具有相同的性能,具有相同的概念,但它更灵活(IMO)

Check out dapper extensions for 'magic' CRUD operations with Dapper: 使用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();
}

Also see this thread for more... 另请参阅主题以获取更多信息

Developers use Drapper because of its performance. 开发人员因其性能而使用Drapper。 For many websites PetaPoco is good enough but if you want to extract all the server 'juice' use Drapper. 对于许多网站来说,PetaPoco已经足够好了,但是如果你想提取所有服务器'果汁',请使用Drapper。 In fact it is the ORM used by Stackoverflow. 实际上它是Stackoverflow使用的ORM。 You can see all ORM performance comparison here 您可以在此处查看所有ORM性能比较

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

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