[Solved] How do I use Dapper.Contrib with FluentMap to update an entity with an identity column?

Maccurt Asks: How do I use Dapper.Contrib with FluentMap to update an entity with an identity column?
I have a class called Business, which has a property Id that is a identity field in MS SQL Server database. When I do an INSERT, it works properly. If I do the following:


I get an error:

invalid column name ‘id” the column in the DB is BusinessId

I have mapped it to Id as below:

public class BusinessMap : EntityMap<Business>
        public BusinessMap()
            Map(x => x.Id).ToColumn("BusinessId");                

Now keep in mind my INSERT works. I tried adding the Key attribute to the class

    public class Business {
        public int Id { get; set; }
        public string Name { get; set; }

My work around (which I hate, but is better than nothing):
I decided to just call a SP to do this, which sort of sucks because I was hoping dapper could handle this.

                param: new { businessId = business.Id, business.Name, business.LocatorUrl, business.Website }, commandType: CommandType.StoredProcedure);

I don’t know why we are forced to conclude that every identity column in our database is named “ID”, that is ludicrous in my opinion, and I don’t think I need to justify my schema design, it should let me change it. Now anytime a field is added, I have to change the SP and the code to call the SP, I will use this until I found the real answer.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.