neisbut / EntityFramework.MemoryJoin

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

Incorrect syntax near 'LIMIT' exception thrown when joining on memory list with 0 entries #8

Closed thixson closed 4 years ago

thixson commented 5 years ago

I have a simple query which joins on an in-memory list.

`var taxTableIds = taxTables.Select(a => new { TaxTableId = a.Id }).ToList(); var ttQueryable = _dbContext.FromLocalList(taxTableIds);

            var taxBrackets = await (from tb in Retrieve<Data.Models.Tax.TaxBrackets>()
                                     join tt in ttQueryable on tb.TaxTableId equals tt.TaxTableId
                                     select tb)
                                     .ToListAsync();

            var taxBracketsPublish = taxBrackets.Select(a => new TaxBracketsPublish
            {
                PublishId = publishLog.Id,
                StoreNumber = storeHelper.StoreNumber,
                SatelliteNumber = storeHelper.SatelliteNumber,
                Id = a.Id,
                TableId = a.TaxTableId,
                LeftValue = a.LeftValue,
                RightValue = (decimal)a.RightValue,
                TaxValue = a.TaxValue,
                StartRepeat = a.StartRepeat,
                RestaurantId = storeHelper.RestaurantId
            }).ToList();

            return taxBracketsPublish;`

However, I'm getting an "Incorrect syntax near 'LIMIT'.", which is strange, because I don't believe LIMIT syntax is even supported in T-SQL.

The query produced the LINQ does indeed have LIMIT syntax: SELECT [tb].[Id], [tb].[LastModifiedByUserId], [tb].[LastModifiedDT], [tb].[LeftValue], [tb].[RightValue], [tb].[StartRepeat], [tb].[TaxTableId], [tb].[TaxValue], [tb].[TransactionId], [t].[TaxTableId] FROM [Tax].[TaxBrackets] AS [tb] INNER JOIN ( SELECT CAST([x].[long1] AS int) AS [TaxTableId] FROM ( SELECT * FROM (VALUES (NULL, NULL)) AS __gen_query_data__ (id, long1) LIMIT 0 ) AS [x] ) AS [t] ON [tb].[TaxTableId] = [t].[TaxTableId]

I suspect that the issue here (as opposed to in other instances where this same construction appears to work fine) is that the taxTables array has 0 entries.

Is there any way to work around this?

neisbut commented 5 years ago

Hi @thixson , this is definitely a bug! Thanks for reporting this, I will fix it soon!

neisbut commented 5 years ago

Hi @thixson , fixed in the latest release. Pleae check when possible. Thanks!

neisbut commented 4 years ago

Closed due to inactivity