Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple Select not working #133

Open
jasonhjohnson opened this issue Feb 24, 2017 · 3 comments

Comments

2 participants
@jasonhjohnson
Copy link

commented Feb 24, 2017

Hi,

I just posted this issue to the EF Core Github and StackOverflow this morning, but as it turns out, the issue is due to something with EF Plus' query filters: aspnet/EntityFrameworkCore#7706 and http://stackoverflow.com/questions/42441235/simple-linq-select-not-working.

When I add the "AsNoFilter()" to my query it works as expected.

Thanks,
Jason

@JonathanMagnan JonathanMagnan self-assigned this Feb 26, 2017

@JonathanMagnan

This comment has been minimized.

Copy link
Member

commented Feb 26, 2017

Hello @jasonhjohnson ,

Thank you for reporting this issue.

Could you provide me the filter you used? I have tried to replicate it unsuccessfully.

Best Regards,

Jonathan

@jasonhjohnson

This comment has been minimized.

Copy link
Author

commented Feb 27, 2017

Hi @JonathanMagnan

I'm using several filters so I'm not exactly sure which one is causing the issue, but here are the filters:

this.context.Filter<IBaseEntityWithTenant>(QueryFilterType.Tenant, q => q.Where(x => x.TenantId == tenantId));
this.context.Filter<IBaseEntityWithTenantAndContact>(QueryFilterType.TenantWithContact, q => q.Where(x => x.TenantId == tenantId));
this.context.Filter<IPlant>(QueryFilterType.TenantForPlant, q => q.Where(x => x.Plant.TenantId == tenantId));
this.context.Filter<ITemplate>(QueryFilterType.TenantForTemplate, q => q.Where(x => x.Template.Plant.TenantId == tenantId));
this.context.Filter<IOrder>(QueryFilterType.TenantForOrder, q => q.Where(x => x.SalesOrder.Plant.TenantId == tenantId));
this.context.Filter<IItem>(QueryFilterType.TenantForItem, q => q.Where(x => x.Item.Plant.TenantId == tenantId));
                  
// Soft delete
this.context.Filter<IBaseEntity>(QueryFilterType.SoftDelete, q => q.Where(x => !x.IsDeleted));

Thanks,
Jason

@JonathanMagnan

This comment has been minimized.

Copy link
Member

commented Feb 27, 2017

Hello @jasonhjohnson ,

Thank you, I have enough information to understand the issue now.

Unfortunately, this issue (even if it appears) is not caused by our library but because Entity Framework Core doesn't handle yet correctly the cast method.

Here is an example how to reproduce it without our library:

using (var ctx = new CurrentContext())
{
	int keyId = 1;

	var ids = ctx.MyTables
		.Cast<IMyTable>()
		.Cast<MyTable>()
		.Where(x => x.SomeKey.Equals(keyId))
		.Select(x => x.MyFieldIntegerIWant)
		.ToList();
}

public class IMyTable
{
            
}

public class MyTable : IMyTable
{
    public int MyTableId { get; set; }
    public int SomeKey { get; set; }
    public int MyFieldIntegerIWant { get; set; }
}

The same LINQ work perfectly under EF6.

In short, it seems to be caused by our library since you filter using an interface. So to apply the filter, our library need to cast first into "IMyTable" and apply the filter then cast it back to "MyTable" which is similar to this scenario.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.