0

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

Krolock
  • 59
  • 1
  • 5
  • Which EF version is this? – Gert Arnold Sep 20 '13 at 11:51
  • Which database and database version are you using? – Slauma Sep 20 '13 at 17:41
  • Is it CodeFirst or edmx? Is the precision and scale set correctly in your model configured the same way as it is in the database? – Pawel Sep 23 '13 at 02:29
  • @Slauma and Pawel: I am using MySQL 5.5.27 an CodeFirst. The column for the decimal attributes are configured automatically as decimal(18,2). – Krolock Sep 23 '13 at 06:21
  • The loading of the values work fine if I load a single value or if loading collections for the first two "includes". Only for the third or later "includes" the values are loaded without comma – Krolock Sep 23 '13 at 06:24
  • I suspect that's a bug in the MySQL connector. Are you using the latest version of the connector? If not, I'd try to update first. If that doesn't help report as possible bug at MySQL support. – Slauma Sep 23 '13 at 10:37
  • @Slauma: Sadly negativ. I am using the latest 6.7.4.0 version of MySql.Data and MySql.Web and 6.7.4.1 of MySQL.Data.Entities. I have also updated my MySQL db from 5.5.27 to 5.6.13, but with the same result – Krolock Sep 23 '13 at 14:28

0 Answers0