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:
_db.Update(business);
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
[Table("Business")]
public class Business {
[Key]
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.
_db.Query("BusinessUpdate",
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.