I am using EF6 to query data from a database. The database existed before the code and belongs to another application, so I cannot modify the database at all. I believe I am using a code first approach, even though the database already exists(Forgive me as I'm new to EF). The issue is that I am not able to pull back data for a column that is setup as follows;
[Column("ITEM_QTY")]
public decimal ItemQuantity { get; set; }
Now if I rename the property to ITEM_QTY, it pulls the data correctly. I'm not sure what I'm missing. I can pull data from any other field correctly, but this field returns 0 regardless of whats in the DB. Can anyone provide any direction?
In another discussion, someone had suggested a possible issue with the underscores in the column name. Not sure if that could be it, but adding for info. Thanks.
Edit: Adding code used to query database. Note that this was setup before I started working on the project, so following same convention;
var t = this.Database.SqlQuery<InventoryDb>("select top 100 * from COMPANY_INVENTORY with (NOLOCK) where COMPANY = @CompanyName",
new SqlParameter("CompanyName", companyName)).ToList();
[Column("ITEMQTY")]
and see if that works? Maybe there is some implicit mapping configuration that strip the underscore out.Column
attribute). This annotation should work no problem. Can you post the line which brings you no data?top 100 *
totop 100 [column1], [column2],[column3]
instead. This way you can even rename the columnITEM_QTY
toItemQuantity
and call it a day.