Comments (12)
Hi @tarockx, thank you for the feedback! I'll be able to work on this next friday.
from detached-mapper.
Hello @leonardoporro , have you had any chance to look at this? Any progress?
from detached-mapper.
Hi @tarockx,
Yes, some progress... would you like to give it a try?
It's not completed, so for the moment, the discriminator needs to be set up in Detached too.
Please take a look here Line 68.
If it works, next step would be to create a Convention to copy the configuration automatically.
Sorry for the delay, I have very limited time to work on this.
from detached-mapper.
published 6.0.5, it doesn't need to be manually configured anymore.. (if it works).
from detached-mapper.
Thank you for your work, really appreciated, I will surely test it as soon as I have the time and provide feedback
from detached-mapper.
Hello Leonardo.
From my preliminary tests, I can confirm it seems to be working correctly! Thank you very much for your work and dedication 👍
from detached-mapper.
Awesome, still need to work on back references when using inheritance...
But will close this for now.
Thanks for the feedback and for the testing.
Stars / shares / help is always welcome!
from detached-mapper.
Hi Leonardo ;) thank you for your nice package. In my tests i can confirm that Detached finds the correct Discriminator but i get this error message:
2 is not a valid value for discriminator in entity My.Wonderful.Entity
my Discriminator is set up like this:
modelBuilder.Entity<RollenBase>()
.HasDiscriminator(r => r.RollenTyp)
.HasValue<KontaktRolle>(1)
.HasValue<BauvorhabenKontaktRolle>(2)
.HasValue<PersonalRolle>(3);
I tried it with strings as well already.
modelBuilder.Entity<RollenBase>()
.HasDiscriminator(r => r.RollenTyp)
.HasValue<KontaktRolle>(nameof(KontaktRolle))
.HasValue<BauvorhabenKontaktRolle>(nameof(BauvorhabenKontaktRolle))
.HasValue<PersonalRolle>(nameof(PersonalRolle));
But I got the same error message...
BauvorhabenKontaktRolle is not a valid value for discriminator in entity My.Wonderful.Entity
My classes are very simple:
public abstract class RollenBase
{
[Key]
public int Id { get; set; }
public string RollenTyp { get; set; }
public string Name { get; set; }
}
public class BauvorhabenKontaktRolle : RollenBase
{
public int RollenId { get; set; }
//some props
}
And my DTO has only three properties.
public class BauvorhabenKontaktRolleDTO
{
public int Id { get; set; }
public string Name { get; set; }
public string RollenTyp {get; set;}
}
Did I configured something wrong?
Thank you for your help and work ;).
from detached-mapper.
This works for me...
using System.ComponentModel.DataAnnotations;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Detached.Mappers.EntityFramework;
using System.Diagnostics;
namespace Test
{
public class Program
{
public static async Task Main(string[] args)
{
TestDbContext context = await TestDbContext.CreateAsync("inheritance_test");
var r1 = context.Map<RollenBase>(new BauvorhabenKontaktRolleDTO
{
Id = 1,
Name = "kontakt",
RollenTyp = nameof(KontaktRolle)
});
var r2 = context.Map<RollenBase>(new BauvorhabenKontaktRolleDTO
{
Id = 2,
Name = "bauvorhabenKontakt",
RollenTyp = nameof(BauvorhabenKontaktRolle)
});
var r3 = context.Map<RollenBase>(new BauvorhabenKontaktRolleDTO
{
Id = 3,
Name = "personalRolle",
RollenTyp = nameof(PersonalRolle)
});
Debug.Assert(r1.GetType() == typeof(KontaktRolle));
Debug.Assert(r2.GetType() == typeof(BauvorhabenKontaktRolle));
Debug.Assert(r3.GetType() == typeof(PersonalRolle));
Console.WriteLine("it works!");
}
}
public abstract class RollenBase
{
[Key]
public int Id { get; set; }
public string RollenTyp { get; set; }
public string Name { get; set; }
}
public class BauvorhabenKontaktRolle : RollenBase
{
public int RollenId { get; set; }
//some props
}
public class KontaktRolle : RollenBase
{
public int RollenId { get; set; }
//some props
}
public class PersonalRolle : RollenBase
{
public int RollenId { get; set; }
//some props
}
public class BauvorhabenKontaktRolleDTO
{
public int Id { get; set; }
public string Name { get; set; }
public string RollenTyp { get; set; }
}
public class TestDbContext : DbContext
{
public TestDbContext(DbContextOptions<TestDbContext> options)
: base(options)
{
}
public DbSet<RollenBase> RollenBases { get; set; }
protected override void OnModelCreating(ModelBuilder mb)
{
mb.Entity<RollenBase>()
.HasDiscriminator(r => r.RollenTyp)
.HasValue<KontaktRolle>(nameof(KontaktRolle))
.HasValue<BauvorhabenKontaktRolle>(nameof(BauvorhabenKontaktRolle))
.HasValue<PersonalRolle>(nameof(PersonalRolle));
}
public static async Task<DbContextOptions<TestDbContext>> CreateOptionsAsync([CallerMemberName] string dbName = null)
{
var connection = new SqliteConnection($"DataSource=file:{dbName}?mode=memory&cache=shared");
await connection.OpenAsync();
return new DbContextOptionsBuilder<TestDbContext>()
.UseSqlite(connection)
.UseDetached(cfg =>
{
})
.Options;
}
public static async Task<TestDbContext> CreateAsync([CallerMemberName] string dbName = null)
{
var context = new TestDbContext(await CreateOptionsAsync(dbName));
await context.Database.EnsureCreatedAsync();
return context;
}
}
}
from detached-mapper.
Added another fix in 6.06
from detached-mapper.
Hi Leonardo ;) thank you very much for your help.
After upgrading it works fine now.
from detached-mapper.
Inheritance works better in version 6.1.0. Also handling abstract types has been improved.
from detached-mapper.
Related Issues (20)
- Complex properties of entity (Owned entities) cannot be used with EFcore mapper HOT 3
- Issue with ComplexType when using EFCore 8.0 HOT 2
- Map keys to entities and vice versa HOT 1
- [NotMapped] Attribute causes a cast error HOT 2
- Use Alternate Keys (Business Keys) to connect disconnected graph as the primary keys are not part of DTO/Disconnected Entity.
- [NotMapped] Attribut
- Exception creating map on static property HOT 1
- Mapping EF child collection of entities with Identity HOT 5
- Upon inserting entities return the newly seeded values for primary keys HOT 3
- lncrease the verbosity of mapping errors HOT 1
- context disposed in MapAsync HOT 3
- No factory for Optional<Guid?> -> Guid HOT 13
- Map a collection of DTOs to entities HOT 4
- Invalid cast when mapping List<T> to Collection<T> (or any derived Collection) HOT 4
- Ignore Data Annotation HOT 5
- GraphQL and Detached mapper HOT 7
- Aggregation doesn't seem to work properly HOT 10
- Prerelease .Net 8 HOT 5
- Updating a composite collection removes one entry HOT 5
- MapperException: Can't find a concrete type for abstract type or interface 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 detached-mapper.