Creating a class with many properties with converter gives error

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Unknown
    • 9.0.1, 8.3.1
    • Affects Version/s: 9.0.0
    • None
    • None
    • Dotnet Drivers
    • Not Needed
    • Hide

      Fixed by implementing Alternate keys in EF-207.

      Show
      Fixed by implementing Alternate keys in EF-207 .
    • None
    • None
    • None
    • None
    • None
    • None

      Description:

      When creating a class that has a custom convert over the Id, and another property with another converter, an error occures

      NotSupportedException: Alternate keys are not supported by the MongoDB EF Core Provider.

       

       

      Example of class

       

      public class A : TrackableEntity<AId>
      {		
        public A(AId id) : base(id) { }		
        public AT Typo { get; set; } // This causes the error
        public string T { get; set; } = string.Empty;
      }
      public record AId(Guid Value) : EntityId(Value);
      public record AT(string Value); 

      Model builder

       

       

      public class EventsDbContext(DbContextOptions<EventsDbContext> options) : BaseDbContext<EventsDbContext>(options)
      {		
      protected override void OnModelCreating(ModelBuilder modelBuilder)		{				
      modelBuilder.Entity<A>()
        .HasKey(a => a.Id);
      
      modelBuilder.Entity<A>()						             .Property(a => a.Id)						.HasConversion(a => a.Value, a => new AId(a))						.HasElementName("_id");
      
      // Also without adding the property with the conversion, the error still occures				
      modelBuilder.Entity<A>()						.Property(x => x.Typo)					
      .HasConversion(type => type.Value, type => new AT(type))					.HasElementName("type");
      				
      modelBuilder.Entity<A>()						.Property(a => a.T)						.HasColumnName("t")						.HasMaxLength(100)						
      .IsRequired();
      				
      
      base.OnModelCreating(modelBuilder);		
      }} 

       

       

       

              Assignee:
              Damien Guard
              Reporter:
              Marco Molica
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: