How to use Dapper with code first?

c# dapper entity-framework


My personal preference for the current application which I am working is to go with ORMs for this purpose.

I haven't used any ORMs yet and I have little knowledge about EntityFramework. Recently I heard of Dapper and have thought of using it.

My question is: is it possible in Dapper to use a code first approach to create a database from classes like in EntityFramework?

Is it good idea use EntityFramework for database creation purposes and query using Dapper?

5/27/2019 4:24:59 AM

Accepted Answer

My question is in EntityFramework we have Code first approach to create Database from classes. Likewise is it possible to do in Dapper ?

Not at all. In dapper only map an existing database. Dapper is a set of extenstion methods for IDbConnection that can help you map a retuned data into c# poco classes.

Is it good to combine EntityFramework for that Db creation purpose and query using Dapper?

No. Use one or another. Also if you create a DB using entity framewok it is already mapped into c# classes so there is no need to use dapper.

If not possible, then please suggest any workaround for if it is there.

Use Entity framework code first. It is simply awesome. You just have to create model classes with some data annotations which you have to do anyway if you use ORM and you basically have whole database and data access layer ready to use. You can also use DB first or model first in Entity frameowkr if you want. First link form google seems to be a good tutorial on code first:

10/18/2019 6:23:46 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow