Comments (3)
When reading a collection of entities, you either need to use .Include(area => area.Areas)
or execute a group join. There are unit tests for both scenarios:
Including a collection:
Using a group join:
I treat any object with its own BsonId
(or Key
) property as a top-level entity, and I do not serialize them as part of the document. Instead, I serialize the necessary information to create a join to read the child element (e.g.: the id of the child object if that object doesn't contain a reference back to the parent). This saves space in the persisted document and allows for a much more flexible use of the collection.
from entityframeworkcore.
@crhairr when use var m = await Context.Set().Where(p => p.Name == "XX")
.Include(p => p.Parent)
.Include(p => p.Areas)
.ToListAsync();
Still error,can make a sample in test unit?
fail: System.Linq.Expressions[3721]
异常信息
System.ArgumentException: Property 'MongoDB.Bson.ObjectId Id' is not defined for type 'System.Collections.Generic.ICollection1[Fengpin.Dcp.Entity.BusinessEntity.Area]' Parameter name: property at System.Linq.Expressions.Expression.Property(Expression expression, PropertyInfo property) at System.Linq.Expressions.Expression.MakeMemberAccess(Expression expression, MemberInfo member) at Blueshift.EntityFrameworkCore.MongoDB.Query.ExpressionVisitors.MongoDbMemberAccessBindingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression) at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at Blueshift.EntityFrameworkCore.MongoDB.Query.MongoDbEntityQueryModelVisitor.ReplaceClauseReferences(Expression expression, IQuerySource querySource, Boolean inProjection) at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitGroupJoinClause(GroupJoinClause groupJoinClause, QueryModel queryModel, Int32 index) at Remotion.Linq.Clauses.GroupJoinClause.Accept(IQueryModelVisitor visitor, QueryModel queryModel, Int32 index) at Remotion.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection
1 bodyClauses, QueryModel queryModel)
at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateAsyncQueryExecutor[TResult](QueryModel queryModel)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileAsyncQueryCore[TResult](Expression query, IQueryModelGenerator queryModelGenerator, IDatabase database)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass22_01.<CompileAsyncQuery>b__0() at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func
1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddAsyncQuery[TResult](Object cacheKey, Func1 compiler) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileAsyncQuery[TResult](Expression query) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query) at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression) at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable
1.System.Collections.Generic.IAsyncEnumerable.GetEnumerator()
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.IncludableQueryable2.System.Collections.Generic.IAsyncEnumerable<TEntity>.GetEnumerator() at System.Linq.AsyncEnumerable.Aggregate_[TSource,TAccumulate,TResult](IAsyncEnumerable
1 source, TAccumulate seed, Func3 accumulator, Func
2 resultSelector, CancellationToken cancellationToken)
at Fengpin.Dcp.ApiService.Controllers.AreaController.AreaInsert(Area area) in D:\个人\风聘\datacenter\Fengpin.Dcp.ApiService\Controllers\AreaController.cs:line 45
at lambda_method(Closure , Object )
at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at System.Threading.Tasks.ValueTask`1.get_Result()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()
from entityframeworkcore.
@crhairr I try many times, self loop refrence read still error
from entityframeworkcore.
Related Issues (20)
- Support for complex property HOT 1
- How can I use dotnet ef dbcontext scaffold HOT 1
- Multiple DbCntexts select query can't work concurrently. HOT 13
- DbSet.Find throws InvalidOperationException HOT 2
- dbContext.DBSet.FirstOrDefault(e => e.FirstName == "xx") missing filter in MongoQueryable HOT 5
- bug: can not modify child HOT 7
- self refrence still can not work HOT 1
- Does this work with IdentityServer4 ? HOT 1
- MissingMethodException in Blueshift.EntityFrameworkCore.MongoDB.Metadata.Conventions.MongoDbRegisterKnownTypesConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder) when using EF Core 2.2 HOT 2
- Wiki Getting Started Installing EFCore-MongoDb error HOT 1
- .NETCore 3 Preview 4 MongoDB.Driver needs upgrade HOT 2
- Still i got this Efcore internal classes problem HOT 1
- Get ObjectDisposedException when execute same query on differend DbContext instances
- Method not found exception
- Entity Framework 3.0 support? HOT 3
- What is the status of tis project? HOT 1
- Hangs on UseMongoDb HOT 2
- Missing Implementation for method HOT 1
- Missing Implementation for method 'get_Info' HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from entityframeworkcore.