本文介绍了执行插入和更新与小巧玲珑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我感兴趣的是用小巧玲珑的 - 但我可以告诉它仅支持查询和执行。我没有看到,小巧玲珑包括插入和更新对象的一种方式。

I am interested in using Dapper - but from what I can tell it only supports Query and Execute. I do not see that Dapper includes a way of Inserting and Updating objects.

由于我们的项目(大多数项目?)需要做的插入和更新,什么是做插入和更新一起短小精悍的最佳实践?

Given that our project (most projects?) need to do inserts and updates, what is the best practice for doing Inserts and Updates alongside dapper?

preferably我们就不必诉诸参数建筑物等的ADO.NET方法。

Preferably we would not have to resort to the ADO.NET method of parameter building, etc.

最好的答案,我可以在这一点上拿出是使用LinqToSQL插入和更新。有没有更好的答案吗?

The best answer I can come up with at this point is to use LinqToSQL for inserts and updates. Is there a better answer?

推荐答案

我们正在研究建立几个助手,还是决定API和这样下去核心与否。参见:<一href=\"http://$c$c.google.com/p/dapper-dot-net/issues/detail?id=6\">http://$c$c.google.com/p/dapper-dot-net/issues/detail?id=6进步。

We are looking at building a few helpers, still deciding on APIs and if this goes in core or not. See: http://code.google.com/p/dapper-dot-net/issues/detail?id=6 for progress.

在此同时,你可以做以下

In the mean time you can do the following

val = "my value";
cnn.Execute("insert Table(val) values(@val)", new {val});

cnn.Execute("update Table set val = @val where Id = @id", new {val, id = 1});

诸如此类

另请参见我的博客文章:That恼人的INSERT问题

See also my blog post: That annoying INSERT problem

这篇关于执行插入和更新与小巧玲珑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 11:00