-
Notifications
You must be signed in to change notification settings - Fork 166
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
EF6 and EF Core version controversy #102
Comments
I don't understand: What do you mean by LinqKit types? And you can just use |
Maybe you can provide an example project ? |
No, I can't use compile switches, because I need EF6 and EF Core both working :-) |
So you want one project where you want to use EF6.3 and EFCore??? |
Basically yes. |
Can be solved using And see my PR on https://github.com/leotsarev/linqkit-namespace-controversy |
Thanks for help! Do you think that having workaround in terms of AsExpandable6/AsExpandableCore and Invoke6/InvokeCore in LinqKit directly won't hit cost/benefit bar? |
Adding these workaround methods is also possible.
I'll check if this can be done easily, or that some complex changes are needed. |
@leotsarev var ef6Ctx = new Ef6Context();
var foo = await ef6Ctx.FooSet.AsExpandableEF().ToListAsync();
var coreCtx = new CoreContext();
var bar = await coreCtx.BarSet.AsExpandableEFCore().ToListAsync(); |
@leotsarev Could you test this? |
Yep, we'll try to |
@leotsarev Any progress on testing this? |
Sorry for delay. Seems that InvokeEF/InvokeEFCore are missing
|
Preview-04 should be available on MyGet |
@StefH, any way you can upload the preview to Nuget.org? |
@leotsarev Can you please verify? @ynauls I'll upload the preview-04 also to NuGet in some time. |
@ynauls version 1.1.17-preview-04 is uploaded to NuGet |
Sorry again for slow replies. No, Invoke is not working for us. using System;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using LinqKit;
using MyLinqKit;
using MyLinqKitCore;
namespace EntityPlusEntityCore
{
class Program
{
static async Task Main()
{
Expression<Func<EfModel, bool>> idExpr = x => x.Id == 5;
var context = new EfContext();
var x1 = await context.EfModels
.AsExpandableEF()
//.MyWhere(idExpr)
.Where(x => idExpr.InvokeEF(x))
.MyCountAsync();
Expression<Func<EfModelCore, bool>> idExprCore = x => x.Id == 5;
var contextCore = new EfContextCore();
var x2 = await contextCore.EfModels
.AsExpandableEFCore()
//.MyWhere(idExprCore)
.Where(x => idExprCore.InvokeEFCore(x))
.MyCountCoreAsync();
}
}
} Neither version are working: EF6 version: |
Does the code work when you don't call invoke manually? Like my answer in this issue #105 |
yes |
Hi @StefH, This works for Where() methods but not within Select() (projections) where it is required to manually call Invoke on the Func expressions. I'm in the same situation where i'm working with both EF and EFCore for the foreseeable future because my supplier only provides an adapter for EF currently. [..]
.Select(x => new ArticleContract()
{
deliveryOrderBook = bookConverter.InvokeEF(x.order.BESTELBKCODE),
})
[..] System.NotSupportedException: LINQ to Entities does not recognize the method 'Datatypes.Briljant.EF.Semantics.BestellingBoek InvokeEF[String,BestellingBoek](System.Linq.Expressions.Expression`1[System.Func`2[System.String,Datatypes.Briljant.EF.Semantics.BestellingBoek]], System.String)' method, and this method cannot be translated into a store expression.
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.DefaultTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.UnaryTranslator.TypedTranslate(ExpressionConverter parent, UnaryExpression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter parent, MemberInitExpression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter parent, MemberInitExpression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input, DbExpressionBinding& binding)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Convert()
at System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass43_0.<GetResultsAsync>b__1()
at System.Data.Entity.Core.Objects.ObjectContext.<ExecuteInTransactionAsync>d__156`1.MoveNext()
[Omitted for brevity] Is there intention to fix this? Thank you in advance. |
Consider following scenario.
Project A references both LinqKit and EF6 and has following code:
Now we need adding new context with Bar data to our application, and choosing to use new brand shine EF Core.
We need to add references (may be transitional) to EF Core and
LinqKit.Microsoft.EntityFrameworkCore
. Than we try to add following code toLoader.cs
Oops, we get compile error about not able to resolve
AsExpandable
,Invoke
andToArrayAsync
. Latter is pretty easy to fix - we can rename namespace or just refactor loading bar toBarLoader.cs
Now compiler could figure
ToArrayAsync
, but still fails to figure LinqKit types between LinqKit.EntityFramework and LinqKit.Microsoft.EntityFrameworkCore.Note that for this to fail it enough to have transitive dependency to LinqKit somewhere in your tree.
There is two problems that lead to that:
We explored trying to wrap LinqKit in our helper lib with different namespaces, but failed.
It's ok to wrap AsExpandable() to AsExpandable6() and AsExpandableCore(), but wrapping Invoke failed (as expected, because it checked on visiting expression tree).
Proposed solutions:
I'm willing to contribute, but of course I need approval first.
The text was updated successfully, but these errors were encountered: