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

Join DbSets in different DbContexts #13775

Closed
armanpetrosyan23 opened this issue Oct 26, 2018 · 10 comments

Comments

Projects
None yet
4 participants
@armanpetrosyan23
Copy link

commented Oct 26, 2018

How to join two DbSet<> in different db contexts in EF Core? I have written the following code: Here I have got NullReferenceException

Exception message:
System.ArgumentNullException

Message=Value cannot be null.
Parameter name: entityType
Source=Microsoft.EntityFrameworkCore.Relational

Code
var collections = (from l in _logcontext.Logs join p in _applicationdbcontext.Users on l.UserID equals p.Id select new { i = l.TableName }).ToList();

ScreenShot

capture

@smitpatel

This comment has been minimized.

Copy link
Contributor

commented Oct 26, 2018

Duplicate of #11101

@smitpatel smitpatel marked this as a duplicate of #11101 Oct 26, 2018

@smitpatel

This comment has been minimized.

Copy link
Contributor

commented Oct 26, 2018

Which version of EF Core are you using?

@armanpetrosyan23

This comment has been minimized.

Copy link
Author

commented Oct 26, 2018

I use ef core 2.1 version

@armanpetrosyan23

This comment has been minimized.

Copy link
Author

commented Oct 26, 2018

@smitpatel #11101 here is writed that this issue has been solved in 2.1 version and even if i use low version for example 2.0.3 i only see followin exception notsuportedoperatiom but as we see throw diferent exception

@armanpetrosyan23

This comment has been minimized.

Copy link
Author

commented Oct 29, 2018

@smitpatel ?????

@smitpatel

This comment has been minimized.

Copy link
Contributor

commented Oct 29, 2018

@armanpetrosyan23 - We will need full repro code here to investigate in the issue.

@armanpetrosyan23

This comment has been minimized.

Copy link
Author

commented Oct 29, 2018

@smitpatel
That error occurs everywhere and our source code does not matter

@armanpetrosyan23

This comment has been minimized.

Copy link
Author

commented Oct 29, 2018

@smitpatel This is my project link where i occurs problems
https://github.com/armanpetrosyan23/Test_Seed.git

@nfdevil

This comment has been minimized.

Copy link

commented Nov 6, 2018

I'm having the same issue when trying to join my ASP.NET Core Identity dbcontext with my ApplicationDbContext:

_dbContext.Comments.Join(_identityDbContext.Users, comment => comment.CreatedById, user => user.Id, (comment, user) => new { comment.Body, comment.Id });

When using the same DbContext in the join, this works perfectly:

_dbContext.Comments.Join(_dbContext.HospitalizationRequests, comment => comment.HospitalizationRequestId, request => request.Id, (comment, request) => new { comment.Body, comment.Id })

I'm receiving the following error:

"Value cannot be null. Parameter name: entityType"

Both DbContexts are using the same database, but are on other schema's:

_dbContext is on schema "HospitalizationRequests"
_identityDbContext is on schema "Authz"

I'm using EF 2.1.4 and AspNetCore.App 2.1.1

Hope this helps when trying to solve this.

@smitpatel smitpatel added the type-bug label Nov 6, 2018

@smitpatel smitpatel marked this as not a duplicate of #11101 Nov 6, 2018

smitpatel added a commit that referenced this issue Nov 6, 2018

Regression Test for joining DbSet from different contexts
Issue: We were checking for QueryProvider being the same except for the path when we accessing DbSet property on DbContext which is converted to ConstantExpression of EntityQueryable

Fixed by #13862

Resolves #13775
@smitpatel

This comment has been minimized.

Copy link
Contributor

commented Nov 6, 2018

This is a bug. We missed out specific code path when DbSet properties on context are used directly. This has been fixed in new funcletizer already.

smitpatel added a commit that referenced this issue Nov 6, 2018

Regression Test for joining DbSet from different contexts (#13901)
Issue: We were checking for QueryProvider being the same except for the path when we accessing DbSet property on DbContext which is converted to ConstantExpression of EntityQueryable

Fixed by #13862

Resolves #13775

@smitpatel smitpatel self-assigned this Nov 6, 2018

@ajcvickers ajcvickers added this to the 3.0.0 milestone Nov 7, 2018

@smitpatel smitpatel closed this Nov 15, 2018

@ajcvickers ajcvickers modified the milestones: 3.0.0, 3.0.0-preview2 Feb 6, 2019

@ajcvickers ajcvickers changed the title Joining DbSet<>s in differend DbContext Join DbSets in different DbContexts Mar 1, 2019

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.