Is there a way to map column names to properties from my entity using Dapper?

c# dapper database stored-procedures

Question

I'm considering in using dapper for my project, but first, I need to know if it:

1-) Can it map column name to my class properties? In my project, i have legacy tables that has no cool names.

2-) It works well with stored procedures? All my queryes relies on stored procedures. Its a company determination.

Thanks

Popular Answer

To map column names to class properties you can do something like this -

class YourClass {
   public int id { get; set; }
   public string name { get; set; }
}

Then -

var yourclasscollection = connection.Query<YourClass>(@"select notcoolid as id, notcoolname as name from legacytable");



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why