I've stumbled across a situation where some fields in my model are not being populated. It has something to do with the order of fields in the query.
Here is the repro example for Northwind.
public class OrderModel
{
[Display(Name = "Order Id")]
public int OrderId { get; set; }
[Display(Name = "Customer Id")]
public string CustomerId { get; set; }
[Display(Name = "Company Name")]
public string CompanyName { get; set; }
[Display(Name = "Employee Id")]
public int? EmployeeId { get; set; }
[Display(Name = "Order Date")]
public DateTime? OrderDate { get; set; }
[Display(Name = "Required Date")]
public DateTime? RequiredDate { get; set; }
[Display(Name = "ShippedDate")]
public DateTime? ShippedDate { get; set; }
[Display(Name = "Freight")]
public decimal? Freight { get; set; }
[Display(Name ="Ship Name")]
public string ShipName { get; set; }
[Display(Name = "Ship Address")]
public string ShipAddress { get; set; }
[Display(Name = "Ship City")]
public string ShipCity { get; set; }
[Display(Name = "Ship Region")]
public string ShipRegion { get; set; }
[Display(Name = "Ship Postal Code")]
public string ShipPostalCode { get; set; }
[Display(Name = "Ship Country")]
public string ShipCountry { get; set; }
}
The first QuerySpec query below will populate the CompanyName field and the second will not. The only difference between them is the position of CustomerFields.CompanyName in the query.
var query = qf.Create()
.From(qf.Customer
.InnerJoin(qf.Order)
.On(CustomerFields.CustomerId == OrderFields.CustomerId))
.Select<OrderModel>(OrderFields.OrderId, OrderFields.OrderDate, OrderFields.RequiredDate,
OrderFields.ShippedDate, OrderFields.CustomerId, CustomerFields.CompanyName,
OrderFields.EmployeeId, OrderFields.Freight,
OrderFields.ShipCity, OrderFields.ShipRegion,
OrderFields.ShipCountry, OrderFields.ShipVia)
.OrderBy(OrderFields.OrderDate.Descending());
var items = new List<OrderModel>();
using (var dataAdapter = new DataAccessAdapter())
{
items = dataAdapter.FetchQuery<OrderModel>(query);
}
var query = qf.Create()
.From(qf.Customer
.InnerJoin(qf.Order)
.On(CustomerFields.CustomerId == OrderFields.CustomerId))
.Select<OrderModel>(OrderFields.OrderId, OrderFields.OrderDate, OrderFields.RequiredDate,
OrderFields.ShippedDate, OrderFields.CustomerId,
OrderFields.EmployeeId, OrderFields.Freight,
OrderFields.ShipCity, OrderFields.ShipRegion,
OrderFields.ShipCountry, OrderFields.ShipVia, CustomerFields.CompanyName)
.OrderBy(OrderFields.OrderDate.Descending());
var items = new List<OrderModel>();
using (var dataAdapter = new DataAccessAdapter())
{
items = dataAdapter.FetchQuery<OrderModel>(query);
}
I'm using the 5.1.2 runtime but the same issue exists for 5.1.1 as well.