I'm looking over some alternatives to EF, and Dapper seems like a pretty good option. But I do have one question. I understand that Dapper, being a Micro ORM doesn't rely on or use a class of models, like EF creates. That being said, what if I still want a buncha models that mirror my db tables? How would I generate them and keep them up to date? Or, at least, some of my tables?
This is from the Dapper GutHub page:
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 });
Assert.Equal(1,dog.Count());
Assert.Null(dog.First().Age);
Assert.Equal(guid, dog.First().Id);
So in this exampe, was the Dog
class manually created?
You will need to create Dog
class by yourself. Dapper is just a wrapper around ADO.NET.
If you want to save time, you could just generate POCO from EF Code first from Database or Entity Framework Power Tools, and use it in Dapper.
Why dont you utilize EF code first migration to maintain/sync your domain models and database. Dapper will work with these entities that generated by EF code first migration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With