1 Star 1 Fork 0

lei.xu.Itachi/Dapper-Extensions

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0
# Introduction Dapper Extensions is a small library that complements [Dapper](https://github.com/SamSaffron/dapper-dot-net) by adding basic CRUD operations (Get, Insert, Update, Delete) for your POCOs. For more advanced querying scenarios, Dapper Extensions provides a predicate system. The goal of this library is to keep your POCOs pure by not requiring any attributes or base class inheritance. Customized mappings are achieved through [ClassMapper](https://github.com/tmsmith/Dapper-Extensions/wiki/AutoClassMapper). **Important**: This library is a separate effort from Dapper.Contrib (a sub-system of the [Dapper](https://github.com/SamSaffron/dapper-dot-net) project). Features -------- * Zero configuration out of the box. * Automatic mapping of POCOs for Get, Insert, Update, and Delete operations. * GetList, Count methods for more advanced scenarios. * GetPage for returning paged result sets. * Automatic support for Guid and Integer [primary keys](https://github.com/tmsmith/Dapper-Extensions/wiki/KeyTypes) (Includes manual support for other key types). * Pure POCOs through use of [ClassMapper](https://github.com/tmsmith/Dapper-Extensions/wiki/AutoClassMapper) (_Attribute Free!_). * Customized entity-table mapping through the use of [ClassMapper](https://github.com/tmsmith/Dapper-Extensions/wiki/AutoClassMapper). * Composite Primary Key support. * Singular and Pluralized table name support (Singular by default). * Easy-to-use [Predicate System](https://github.com/tmsmith/Dapper-Extensions/wiki/Predicates) for more advanced scenarios. * Properly escapes table/column names in generated SQL (Ex: SELECT [FirstName] FROM [Users] WHERE [Users].[UserId] = @UserId_0) * Unit test coverage (150+ Unit Tests) Naming Conventions ------------------ * POCO names should match the table name in the database. Pluralized table names are supported through the PlurizedAutoClassMapper. * POCO property names should match each column name in the table. * By convention, the primary key should be named Id. Using another name is supported through custom mappings. # Installation For more information, please view our [Getting Started](https://github.com/tmsmith/Dapper-Extensions/wiki/Getting-Started) guide. http://nuget.org/List/Packages/DapperExtensions ``` PM> Install-Package DapperExtensions ``` # Examples The following examples will use a Person POCO defined as: ```c# public class Person { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public bool Active { get; set; } public DateTime DateCreated { get; set; } } ``` ## Get Operation ```c# using (SqlConnection cn = new SqlConnection(_connectionString)) { cn.Open(); int personId = 1; Person person = cn.Get<Person>(personId); cn.Close(); } ``` ## Simple Insert Operation ```c# using (SqlConnection cn = new SqlConnection(_connectionString)) { cn.Open(); Person person = new Person { FirstName = "Foo", LastName = "Bar" }; int id = cn.Insert(person); cn.Close(); } ``` ## Advanced Insert Operation (Composite Key) ```c# public class Car { public int ModelId { get; set; } public int Year { get; set; } public string Color { get; set; } } ... using (SqlConnection cn = new SqlConnection(_connectionString)) { cn.Open(); Car car = new Car { Color = "Red" }; var multiKey = cn.Insert(car); cn.Close(); int modelId = multiKey.ModelId; int year = multiKey.Year; } ``` ## Simple Update Operation ```c# using (SqlConnection cn = new SqlConnection(_connectionString)) { cn.Open(); int personId = 1; Person person = cn.Get<Person>(personId); person.LastName = "Baz"; cn.Update(person); cn.Close(); } ``` ## Simple Delete Operation ```c# using (SqlConnection cn = new SqlConnection(_connectionString)) { cn.Open(); Person person = cn.Get<Person>(1); cn.Delete(person); cn.Close(); } ``` ## GetList Operation (with Predicates) ```c# using (SqlConnection cn = new SqlConnection(_connectionString)) { cn.Open(); var predicate = Predicates.Field<Person>(f => f.Active, Operator.Eq, true); IEnumerable<Person> list = cn.GetList<Person>(predicate); cn.Close(); } ``` Generated SQL ``` SELECT [Person].[Id] , [Person].[FirstName] , [Person].[LastName] , [Person].[Active] , [Person].[DateCreated] FROM [Person] WHERE ([Person].[Active] = @Active_0) ``` More information on predicates can be found in [our wiki](https://github.com/tmsmith/Dapper-Extensions/wiki/Predicates). ## Count Operation (with Predicates) ```c# using (SqlConnection cn = new SqlConnection(_connectionString)) { cn.Open(); var predicate = Predicates.Field<Person>(f => f.DateCreated, Operator.Lt, DateTime.UtcNow.AddDays(-5)); int count = cn.Count<Person>(predicate); cn.Close(); } ``` Generated SQL ``` SELECT COUNT(*) Total FROM [Person] WHERE ([Person].[DateCreated] < @DateCreated_0) ``` More information on predicates can be found in [our wiki](https://github.com/tmsmith/Dapper-Extensions/wiki/Predicates). # License Copyright 2011 Thad Smith, Page Brooks and contributors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

暂无描述 展开 收起
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Itachi-proxy/Dapper-Extensions.git
[email protected]:Itachi-proxy/Dapper-Extensions.git
Itachi-proxy
Dapper-Extensions
Dapper-Extensions
master

搜索帮助