Closed rfcdejong closed 4 years ago
Sadly, just adding a Key on an new Id property to PersonAddress doesn't do the trick. Then at runtime it turns into another null reference exception
at lambda_method(Closure , QueryContext , JObject )
at Microsoft.EntityFrameworkCore.Cosmos.Query.Internal.CosmosShapedQueryCompilingExpressionVisitor.QueryingEnumerable`1.Enumerator.MoveNext()
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
at lambda_method(Closure , QueryContext )
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
at MyProject.API.Controllers.PersonController.GetSingleAsync(Guid personId, ICrudServices`1 service) in C:\Repos\MyProject\Controllers\PersonController.cs:line 50
at lambda_method(Closure , Object )
For now I will not use ILinkToEntity and will try to use Automapper directly
If you look up about Owned types you will see the class is contained in the outer entity class, i.e. the data becomes part of the outer entity class. Therefore you can only access that data via the outer class.
This means that the adding ILinkToEntity<PersonAddress>
isn't going to work. You should be using nested DTOs as described in the GenericServices's Wiki.
Using CosmosDb with Entity Framework Core it is not possible to use nested resources. Having the following code:
With some Dto's
EF does not allow to define the entity without a key and using OwnsOne, but I can leave the follow line away.
modelBuilder.Entity<PersonAddress>(pa => pa.HasNoKey());
Setup and then Registering the DtoType's crashes because it expects a primaryKeyProperty on the entity, the entityInfo.PrimaryKeyProperties in DecodedDto contains a property with the value null and then it crashes.