DbSet Include Generates incorrect SQL

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
Simonare
Posts: 4
Joined: Thu 18 Jan 2018 18:15

DbSet Include Generates incorrect SQL

Post by Simonare » Thu 18 Jan 2018 18:20

Code: Select all

public virtual async Task<TEntity> GetByIdAsync(object[] keyValues,
        List<Expression<Func<TEntity, object>>> includes,
        CancellationToken cancellationToken = default(CancellationToken))
    {
        Task<TEntity> model = null;

        foreach (var include in includes)
        {
            if (include.Body.Type.GetInterface(nameof(IEnumerable<TEntity>)) != null)
            { //this part generates SQL Below
                await DbSet.Include(include).LoadAsync(cancellationToken);
                model = DbSet.FindAsync(keyValues, cancellationToken);
            }
            else //this part is working
            {
                var propertyName = ((MemberExpression)include.Body).Member.Name;
                model = DbSet.FindAsync(keyValues, cancellationToken);
                await DbContext.Entry(model.Result).Navigation(propertyName).LoadAsync(cancellationToken);
            }
        }

        if (model == null)
            model = DbSet.FindAsync(keyValues, cancellationToken);

        return await model;
    }
above code returns incorrect SQL which is specified below:

Code: Select all

SELECT "product.MhpProducts".MP_MHP_ID, "product.MhpProducts".MP_PRODUCT_ID, "product.MhpProducts".MP_G_ORDER, "product.MhpProducts".G_END_DATE, "product.MhpProducts".G_INSERT_BY, "product.MhpProducts".G_INSERT_DATE, "product.MhpProducts".G_IS_DELETED, "product.MhpProducts".G_START_DATE, "product.MhpProducts"."MP_WEST_CORE._DOMAIN._ENTITIES._WEST_LIFE._MHP_PRODUCT" FROM MHP_PRODUCT "product.MhpProducts" INNER JOIN ( SELECT "product0".TP_ID FROM TREE_PRODUCT "product0" ) "t" ON "product.MhpProducts".MP_PRODUCT_ID = "t".TP_ID ORDER BY "t".TP_ID
Any Idea about it?

it seems like a Bug

Shalex
Site Admin
Posts: 8247
Joined: Thu 14 Aug 2008 12:44

Re: DbSet Include Generates incorrect SQL

Post by Shalex » Fri 19 Jan 2018 16:49

Please upload a small test project with the corresponding DDL/DML script to ftp://ftp.devart.com (credentials: anonymous / yourEmail).

Post Reply