How to use Dapper with code first?

c# dapper entity-framework


My own choice is to use ORMs for this reason in the application on which I am now working.

I haven't utilized any ORMs yet, and my understanding of EntityFramework is limited. I just learned about Dapper and considered using it.

I want to know whether using a code first strategy to build a database from classes as in EntityFramework is doable in Dapper.

Is it a good idea to create databases using EntityFramework and use Dapper to query them?

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 ?

In no way. Only map an existing database in dapper. Dapper is a collection of IDbConnection extension methods that may be used to convert transformed data into C# POCO classes.

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

No. Choose between the two. Additionally, there is no need to utilize Dapper if you construct a database using Entity Framework since it is already mapped into c# classes.

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

Start by using Entity framework code. Simply said, it is great. You effectively have the whole database and data access layer ready to go; all you need to do is construct model classes with some data annotations, which you must do anyway if you use ORM. If you like, you may also utilize the Entity Framework's DB first or model first approaches. The first Google link seems to be a helpful instruction on coding first:

10/18/2019 6:23:46 AM

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