好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

来自stackoverflow的orm

来自stackoverflow的orm

dapper-dot-net

Simple SQL object mapper for ADO.NET

 

Project Home Downloads Wiki Issues Source

Summary      Updates      People

 

Project Information

 Starred by  313  user s

Activity      High Project feeds Code license Apache License 2.0 Labels
CSharp ,  SQLServer

  Members

sam.saff...@gmail.com , marc.gravell 2 committers

Links

Blogs Sam's Blog Marc's Blog Stack Overflow Blog External links nuget

Dapper - a simple object mapper for .Net

Official Github clone:  https://github.com/SamSaffron/dapper-dot-net

Features

Dapper is a  single file  you can drop in to your project that will extend your  IDbConnection  interface.

It provides 3 helpers:

Execute a query and map the results to a strongly typed List

  Note: all extension methods assume the connection is already open, they will fail if the connection is closed.

public static IEnumerable<T> Query<T>(this IDbConnection cnn, string sql, object param = null, SqlTransaction transaction = null, bool buffered = true)

Example usage:

 public     class     Dog  
{
    public int ? Age { get ; set ; }
    public Guid Id { get ; set ; }
    public string Name { get ; set ; }
    public float ? Weight { get ; set ; }

    public int IgnoredProperty { get { return 1 ; } }
}            
           
var guid = Guid . NewGuid ();
var dog = connection . Query < Dog >( "select Age = @Age, Id = @Id" , new { Age = ( int ?) null , Id = guid });
           
dog . Count ()
    . IsEqualTo ( 1 );

dog . First (). Age
    . IsNull ();

dog . First (). Id
    . IsEqualTo ( guid );

Execute a query and map it to a list of dynamic objects

public static IEnumerable<dynamic> Query (this IDbConnection cnn, string sql, object param = null, SqlTransaction transaction = null, bool buffered = true)

This method will execute SQL and return a dynamic list.

Example usage:

    var   rows   =   connection  .  Query  (  "select 1 A, 2 B union all select 3, 4"  );  

(( int ) rows [ 0 ]. A )
    . IsEqualTo ( 1 );

(( int ) rows [ 0 ]. B )
    . IsEqualTo ( 2 );

(( int ) rows [ 1 ]. A )
    . IsEqualTo ( 3 );

(( int ) rows [ 1 ]. B )
    . IsEqualTo ( 4 );

查看更多关于来自stackoverflow的orm的详细内容...

  阅读:40次