Breeze / breeze.server.net

Breeze support for .NET servers
MIT License
76 stars 62 forks source link

EF 6 with MySql - error #138

Open Nesse opened 2 years ago

Nesse commented 2 years ago

Hi,

I'm using an implementation of EF 6 using a MySql database. This works great. But now I want to use a BreezeController and here I'm getting some errors => String was not recognized as a valid Boolean value

This is only with some requests using the $expand parameter. This is my request:

Products?$filter=(Id eq 576) and (Deleted eq false)&$expand=ProductPictures,ProductCategories,ProductManufacturers,ProductSpecificationAttributes,ProductTierPrices,StockItems/StockUnits/WarehouseLocation,RelatedProducts,CrossSellProducts,BundledProducts,GroupedProducts,ProductPurchasePrices,ProductGroup,ProductTranslations

I've did some debugging and see that the error message comes from Beeze.WebApi2.QueryHelper:

var listQueryResult = Enumerable.ToList((dynamic)queryResult);

Here is my EF setup:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{

    modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); 
    modelBuilder.Properties<decimal>().Configure(c => c.HasPrecision(18, 10));
    modelBuilder.Properties<string>().Configure(c => c.HasColumnType("LONGTEXT"));
    modelBuilder.Properties<bool>().Configure(c => c.HasColumnType("BIT"));

    // base
    base.OnModelCreating(modelBuilder);
}

Does someone knows how to fix this?

steveschmitt commented 2 years ago

At first glance, it seems like the error might be caused by Deleted eq false. What happens if you use Deleted eq 0 ?

Nesse commented 2 years ago

At first glance, it seems like the error might be caused by Deleted eq false. What happens if you use Deleted eq 0 ?

@steveschmitt The error is the same. I Think this is an issue using $expand with more than 1 level deep.

Nesse commented 2 years ago

After some more digging I think the problem is caused by the MySql Connector (MySql.Data.EntityFramework). What are your thoughts?

   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt)
   at System.Convert.ToDecimal(String value, IFormatProvider provider)
   at System.String.System.IConvertible.ToDecimal(IFormatProvider provider)
   at System.Convert.ToDecimal(Object value)
   at MySql.Data.MySqlClient.MySqlDataReader.GetDecimal(Int32 i)
   at MySql.Data.EntityFramework.EFMySqlDataReader.GetDecimal(Int32 ordinal) 
steveschmitt commented 2 years ago

Strange that the error is "String was not recognized as a valid Boolean value", but the stack trace shows that it is trying to convert a field to a decimal.

It looks like the error is happening when it is reading the results, so perhaps one of the table fields is mapped to an incompatible C# type. But which one? You may have to remove your expands one at a time until you find which table has the problem.

steveschmitt commented 1 year ago

Any new info on this one?