dapper

Mapping entity in Dapper

笑着哭i 提交于 2019-11-30 02:37:33
问题 I've just started working with Dapper and I don't seem to find something very simple like mapping an entity to a table in my database: I have a stored procedure: CREATE PROCEDURE [dbo].GetUserById (@UserId int) AS begin SELECT UserId,LastName,FirstName,EmailAddress FROM users WHERE UserID = @UserId end go Then an entity: public class User { public int Id { get; set; } public string LastName { get; set; } public string FirstName { get; set; } public string Email { get; set; } } And a dapper

Why should one use Dapper ? Also can anyone comment on Dapper Vs ADO.NET Pros and Cons [closed]

五迷三道 提交于 2019-11-30 01:31:05
I would like to understand on when would some one really need to think of using Dapper. Also i would like to understand the Pros and Cons of comparing Dapper Vs ADO.NET Dapper is just a tool. What it does is: make it trivially easy to correctly parameterize queries make it trivially easy to execute queries (scalar, multi-rows, multi-grids, and no-results) make it trivially easy to turn results into objects very efficiently and quickly What it doesn't do is: generate a class model for you generate queries for you track objects and their changes so you can just call SubmitChanges() (or whatever)

Any good samples for getting started with Dapper? [closed]

扶醉桌前 提交于 2019-11-29 22:55:44
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. Thanks a lot. Marc Gravell 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). 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

Does Dapper support the like operator?

前提是你 提交于 2019-11-29 20:33:55
Using Dapper-dot-net... The following yields no results in the data object: var data = conn.Query(@" select top 25 Term as Label, Type, ID from SearchTerms WHERE Term like '%@T%'", new { T = (string)term }); However, when I just use a regular String Format like: string QueryString = String.Format("select top 25 Term as Label, Type, ID from SearchTerms WHERE Term like '%{0}%'", term); var data = conn.Query(QueryString); I get 25 rows back in the collection. Is Dapper not correctly parsing the end of the parameter @T ? Sam Saffron Try: term = "whateverterm"; var encodeForLike = term => term

Get DateTime as UTC with Dapper

僤鯓⒐⒋嵵緔 提交于 2019-11-29 20:24:00
I'm using Dapper to map my entities to SQL Server CE. If I save a DateTime with Kind=Utc , when I read it back I get a DateTime with Kind=Unspecified , which leads to all kind of problems. Example: var f = new Foo { Id = 42, ModificationDate = DateTime.UtcNow }; Console.WriteLine("{0} ({1})", f.ModificationDate, f.ModificationDate.Kind); connection.Execute("insert into Foo(Id, ModificationDate) values(@Id, @ModificationDate)", f); var f2 = connection.Query<Foo>("select * from Foo where Id = @Id", f).Single(); Console.WriteLine("{0} ({1})", f2.ModificationDate, f2.ModificationDate.Kind); This

Dapper. Paging

谁都会走 提交于 2019-11-29 20:16:14
I am trying Dapper ORM and I am querying a a Posts table. But I would like to get paged results ... 1 - How can I do this? Isn't there a helper for this? 2 - Can Dapper Query return an IQueryable? Thank You, Miguel 1) Dapper doesn't have a built-in pagination feature. But its not too hard to implement it directly in the query. Example: SELECT * FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY InsertDate) AS RowNum, * FROM Posts WHERE InsertDate >= '1900-01-01' ) AS result WHERE RowNum >= 1 // *your pagination parameters AND RowNum < 20 //* ORDER BY RowNum Requires SQL Server 2005+ 2) Dapper returns

Is there anyway to iterate through a Dapper DynamicParameters object?

纵饮孤独 提交于 2019-11-29 19:16:39
问题 I need to make a generic logger to record certain insert/update statements so that my testers can verify the data being inserted is correct. My first thought was that I would just use a function that accepted DynamicParameters and I would foreach through the DynamicParameters to generate a string to list the parameter's name and value and make them easier to read for the testers. Unfortunately, Dapper.DynamicParameters does not contain a public definition for "GetEnumerator" Here is basic

Dapper and varchars

我只是一个虾纸丫 提交于 2019-11-29 18:57:56
问题 I found the following comment on the Dapper .NET project home page. Dapper supports varchar params, if you are executing a where clause on a varchar column using a param be sure to pass it in this way: Query<Thing>("select * from Thing where Name = @Name", new {Name = new DbString { Value = "abcde", IsFixedLength = true, Length = 10, IsAnsi = true }); On Sql Server it is crucial to use the unicode when querying unicode and ansi when querying non unicode I'm evaluating Dapper for use with a

dapper

大城市里の小女人 提交于 2019-11-29 18:28:40
使用dapper不需要考虑conn是否连接,在执行dapper时自行判断 open状态,如果没有打开它会自己打开。 来源: https://blog.csdn.net/LLLiuwanpeng/article/details/100878268

Generic QueryMultiple with Dapper

风流意气都作罢 提交于 2019-11-29 18:13:38
I have a base repository with a Generic Get method to return Data using Dapper like public T Get<T>(Func<IDbConnection, T> query) { using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["myDB"].ConnectionString)) { return query.Invoke(db); } } However I now have the need to return multiple Data. The DAL query is as below: var multi = db.QueryMultiple(getCarDataSp , new { CustomerID = customerId, Year = year }, commandType: CommandType.StoredProcedure)); var cars = multi.Read<CarDTO>(); var options = multi.Read<CarOptionDTO>(); //wire the options to the cars foreach