任何好的样本入门小巧玲珑? [英] Any good samples for getting started with Dapper?

查看:144
本文介绍了任何好的样本入门小巧玲珑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在已有的项目MVC3上手与精致小巧,虽然它看起来非常好用,我似乎无法找到如何intially设置它的任何教程。任何链接或建议将是非常美联社preciated。

I'm trying to get started with Dapper in an exisiting MVC3 project and although it looks very easy to use, I can't seem to find any tutorials on how to set it up intially. Any links or suggestions would be highly appreciated.

非常感谢。

推荐答案

这是,部分原因是的没有设置的 - 你需要的是一个数据库(它不关心)和一些类(它不关心)。

That is, in part, because there is nothing to set up - all you need is a database (which it doesn't care about) and some classes (which it doesn't care about).

核心方法只是把参数化的SQL,并故意接近LINQ到SQL的基于SQL的方法(提示:我们用短小精悍作为直接下拉更换每当我们得到的问题与LINQ到SQL)。

The core methods just take parameterised SQL, and are deliberately close to LINQ-to-SQL's sql-based methods (hint: we use dapper as a direct drop-in replacement whenever we get issues with LINQ-to-SQL).

如果你想举几个例子,的测试项目包含核心API的例子。

If you want a few examples, the "tests" project contains examples of the core APIs.

如果你的意思是我怎么添加短小精悍 - 两种选择; 添加到项目中一个单独的文件,或一个的NuGet包。该的NuGet pacakge往往滞后一点,但不多。

If you mean "how do I add dapper" - two choices; a single file added to your project, or a nuget package. The nuget pacakge tends to lag a little bit, but not much.

但最终,用法就是:

// get all open orders for this customer
var orders = connection.Query<Order>(
    "select * from Orders where CustomerId = @custId and Status = 'Open'",
    new { custId = customerId }).ToList();

在您的订单类有相匹配的数据库(它是一个非常直接映射)的名称属性。不需要属性;没有特殊的工具是必需的。在我们的例子中,我们倾向于使用LINQ到SQL生成的类的,或者对列的某个子集创建一个特定的类(几个表之间或复合等)。

where your Orders class has properties with names matching the database (it is a very direct map). No attributes are required; no special tooling is required. In our case, we tend to use LINQ-to-SQL generated classes with it, or a specific class created for some subset of columns (or composite between several tables, etc).

这篇关于任何好的样本入门小巧玲珑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆