I have a problem with Entity Framework and eager loading: If I want to load several Collections that contains decimals only the first two includes deliver the correct data. The third include delivers a number without comma separator: Here's my model:
public class ShoppingBasket
{
[Key]
public int ID { get; set; }
public decimal PriceTotal { get; set; }
public ICollection<Article> ArticelsA { get; set; }
public ICollection<Article> ArticelsB { get; set; }
public ICollection<Article> ArticelsC { get; set; }
}
public class Article
{
[Key]
public int ID { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
}
This is the eager loading request:
ShoppingBasket basket = db.Baskets
.Include("ArticelsA")
.Include("ArticelsB")
.Include("ArticelsC")
.First( p => p.ID == id);
// db.Entry(person).Collection("ArticelsC").Load();
And this is the result on my view
aArticles A:
Teller 45,87
Schere 48,70
Feuerzeug 20,00
Articles B:
Pizza 123,14
Burger 99,87
Articles C:
Auto 2314,00
Taxi 7987,00
The prices of Auto in database is 23,14 and Taxi has 79,87 It is not a problem of the view, using the debugger I can see that problem in basket object too.
If I change my includes to ArticlesA, ArticlesC, ArticlesB the values of B are false.
As a quick work around I reload the third collection in line line commented:
db.Entry(person).Collection("ArticelsC").Load();
But this solution generated a second db call or one call per collection that I needed more in future or at a more complex entity structure