neisbut / EntityFramework.MemoryJoin

Extension for EntityFramework for joins to in-memory data
MIT License
56 stars 24 forks source link

Too complex object? #19

Closed DominicArchual closed 2 years ago

DominicArchual commented 3 years ago

I'm experiencing an issue similar to this issue whereby passing a seemingly simple object into FromLocalList results in an error, "Too complex object."

My project is configured for .NET 4.7.2 using EF 6:

  <package id="EntityFramework" version="6.4.4" targetFramework="net472" />
  <package id="EntityFrameworkCore.MemoryJoin" version="0.7.5" targetFramework="net472" />

Any idea what makes this array (which is not so far from the example) too complex for the method to handle? Is .NET 4.7.2 not supported?

    var queryData = new[] {
        new { 
            ProductType = "Hardwood", 
            Manufacturer = "Mohawk Industries", 
            ProductLineName = "Santa Barbara", 
            Price = "10.01",
            NormalizedUOM = "SQ FT"
        },
        new {
            ProductType = "Carpet",
            Manufacturer = "Mohawk Industries",
            ProductLineName = "Celestial Beauty",
            Price = "9.01",
            NormalizedUOM = "SQ FT"
        }
    };

    var items = Context.FromLocalList(queryData);

I have also tried the following but the error returns, "Please include at least one property with Long type."

    var queryData = new ImportModel2[] {
        new ImportModel2 { 
            ProductType = "Hardwood", 
            Manufacturer = "Mohawk Industries", 
            ProductLineName = "Santa Barbara", 
            Price = "10.01",
            NormalizedUOM = "SQ FT"
        },
        new ImportModel2 {
            ProductType = "Carpet",
            Manufacturer = "Mohawk Industries",
            ProductLineName = "Celestial Beauty",
            Price = "9.01",
            NormalizedUOM = "SQ FT"
        }
    };

    var items = Context.FromLocalList(queryData, typeof(ImportModel2));

The class definition of ImportModel2 is as follows:

    public class ImportModel2
    {
        public string ProductType { get; set; }
        public string Manufacturer { get; set; }
        public string ProductLineName { get; set; }
        public string StyleNumber { get; set; }
        public string Width { get; set; }
        public string UOM { get; set; }
        public string Price { get; set; }
        public string NormalizedUOM { get; set; }
    }
neisbut commented 3 years ago

Hi @DominicArchual, yes, as I see you use many strings in your ImportModel2. By default in QueryModelClass which is used internally there are just 3 string fields. You can bypass this limitation by creation custom QueryModelClass and put there as many string properties as you want (just use current version as template https://github.com/neisbut/EntityFramework.MemoryJoin/blob/master/src/EntityFramework.MemoryJoin/QueryModelClass.cs and add more string properties). Don't forget to use your QueryModelClass in DbSet in your context. Hope this helps.

dust63 commented 9 months ago

@neisbut how do you register the extended query model class in the dbcontext, to allow memory join with the extended class ?