{"id":5373,"date":"2014-03-30T21:10:49","date_gmt":"2014-03-30T21:10:49","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/dapper-mapping-column-with-a-property-in-the-model-having-a-diferent-name-and-type-collection-of-common-programming-errors\/"},"modified":"2014-03-30T21:10:49","modified_gmt":"2014-03-30T21:10:49","slug":"dapper-mapping-column-with-a-property-in-the-model-having-a-diferent-name-and-type-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/dapper-mapping-column-with-a-property-in-the-model-having-a-diferent-name-and-type-collection-of-common-programming-errors\/","title":{"rendered":"Dapper mapping column with a property in the model having a diferent name and type-Collection of common programming errors"},"content":{"rendered":"<p>I have a model this model:<\/p>\n<pre><code> public class Member\n    {\n        #region public property\n\n        public int Id { get; set; }\n        public string LastName { get; set; }\n        public string FirstName { get; set; }\n        public AccountState AccountState { get; set; }\n        public GodFatherType GodFatherType { get; set; }\n}\n<\/code><\/pre>\n<p>AccountState and GodFatherType Are both 2 eumerates:<\/p>\n<pre><code> public enum AccountState \n{\n    NotActivated = 0,\n    Activated = 1,\n    Desactived = 2,\n\n}\n\n public enum GodFatherType\n    {\n        Undefined=0,\n        unknown = 1,\n        Correct = 2,\n    }\n<\/code><\/pre>\n<p>In The database I have Id, LastName, FistName, a <code>TinyInt<\/code> AccountstateId et <code>smallint<\/code> GodFatherTypeid, i don&#8217;t would like to change my stored procedure how can I map My class <code>Member<\/code> with the database??<\/p>\n<p>Actually I get only the attributes only Id, LastName, FistName when I execute my stored pocedure with this code:<\/p>\n<pre><code> public sealed class DbContext : IDbContext\n{\n    private bool disposed;\n    private SqlConnection connection;\n\n    public DbContext(string connectionString)\n    {\n        connection = new SqlConnection(connectionString);\n    }\n\n    public IDbConnection Connection\n    {\n        get\n        {\n            if (disposed) throw new ObjectDisposedException(GetType().Name);\n\n            return connection;\n        }\n    }\n\n    public IDbTransaction CreateOpenedTransaction()\n    {\n        if (connection.State != ConnectionState.Open)\n            Connection.Open();\n        return Connection.BeginTransaction();\n    }\n\n    public IEnumerable ExecuteProcedure(string procedure, dynamic param = null, IDbTransaction transaction = null)\n    {\n        if (connection.State == ConnectionState.Closed)\n        {\n            connection.Open();\n        }\n\n        return Dapper.SqlMapper.Query(connection, procedure, param, transaction,\n            commandType: CommandType.StoredProcedure);\n    }\n\n    public int ExecuteProcedure(string procedure, dynamic param = null, IDbTransaction transaction = null)\n    {\n        if (connection.State == ConnectionState.Closed)\n        {\n            connection.Open();\n        }\n\n        return Dapper.SqlMapper.Execute(connection, procedure, param, transaction,\n            commandType: CommandType.StoredProcedure);\n    }\n\n    public void Dispose()\n    {\n        Debug.WriteLine(\"** Disposing DbContext\");\n\n        if (disposed) return;\n\n        if (connection != null)\n        {\n            connection.Dispose();\n            connection = null;\n        }\n\n        disposed = true;\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I have a model this model: public class Member { #region public property public int Id { get; set; } public string LastName { get; set; } public string FirstName { get; set; } public AccountState AccountState { get; set; } public GodFatherType GodFatherType { get; set; } } AccountState and GodFatherType Are both 2 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5373","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5373","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5373"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5373\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}