Closed Akku-21 closed 2 years ago
hi @Akku-21,
The definition of your entity
and Reference
are fine, so it must be the way you are accessing them using GenericServices.
The error you list suggests you have a DTO linked to the Reference
class, e.g class SomeClass LinkToEntity<Reference> { ...
, but you don't need a link an Owned Type as when your entity
is loaded if your DTO has a public Reference Object { get; set; }
then that parameter will automatically filled in by EF Core.
If there is still a problem then please show your DTOs and the GenericServices code that creates an exception.
First of all, thank you for the quick answer. I found out it has to do with .net 6 . I rolled back to .net5 and everything works again.
using (var context = new Context(new DbContextOptions<Context>()))
{
context.Database.EnsureCreated();
var utData = context.SetupEntitiesDirect();
var service = new CrudServices(context, utData.ConfigAndMapper);
where the context only has public DbSet<entity> Entities{ get; set; }
I have no dto linked to the Reference record.
Are you saying that net6 isn't working? Have you updated to version 5.1.0 of the GenericServices library?
yes that is what I am saying. I made a small app from scratch to test it. here are the results:
public class entity
{
[Key]
public long Id { get; set; }
public Reference Object { get; set; }
public Reference Object2 { get; set; }
}
[Owned]
public class Reference
{
[StringLength(50)]
public string Type { get; set; }
}
public class Context:DbContext
{
public Context(DbContextOptions<Context> options)
: base(options)
{
}
public DbSet<entity> Entities { get; set; }
}
public void Test1()
{
var options = SqliteInMemory.CreateOptions<Context>();
using (var context = new Context(options))
{
context.Database.EnsureCreated();
var utData = context.SetupEntitiesDirect();
var service = new CrudServices(context, utData.ConfigAndMapper);
}
}
this will fail. however if you were to use just one field in the entity(remove prop object2) it will work.
thanks Jan
Interesting. I have reproduced this error in this test. I will work on it, but I have other things so might be some days.
Hi @Akku-21,
That was an interesting problem caused to the IEntityType
for an Owned Type class changed in EF Core 6. I'm now using the IsOwned
type which came out in EF Core 5.
will fail with The class Reference was not found in the TestCtx DbContext. The class must be either be an entity class derived from the GenericServiceDto/Async class.