Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceOwnershipBuilder HasDiscriminator #14877

Closed
chris-stormideas opened this issue Feb 28, 2019 · 2 comments
Closed

ReferenceOwnershipBuilder HasDiscriminator #14877

chris-stormideas opened this issue Feb 28, 2019 · 2 comments

Comments

@chris-stormideas
Copy link

I am trying to configure an owned type with inheritance, the domain model being similar to this:

public class TimeZone : FullAuditedAggregateRoot<Guid>
  {
    public virtual string Title { get; set; }
    public virtual string TimeZoneInfoId { get; set; }
    public virtual bool RequiresProvider { get; set; }
    public virtual int SortOrder { get; set; }

    public virtual FeedSetting Feed { get; set; }
}

public abstract class FeedSetting : Entity<Guid>
  {
    public static FeedSetting Empty { get; } = new DirectFeed(Feed.EST);

    protected FeedSetting()
    {
    }

    public abstract Feed GetFeed(TimeZone timezone, Provider provider);
  }
  
  public class ProviderFeedSetting : FeedSetting
  {
    public override Feed GetFeed(TimeZone timezone, Provider provider)
    {
      if (timezone.RequiresProvider && provider != null)
      {
        return provider.Feed;
      }

      return Empty.GetFeed(timezone, provider);
    }
  }

  public class DirectFeedSetting : FeedSetting
  {   
    public virtual Feed Feed { get; protected set; } = Feed.EST;

    protected DirectFeedSetting() : base()
    {
    }

    public DirectFeedSetting(Feed feed)
    {
      Feed = feed;
    }
    
    public override Feed GetFeed(TimeZone timezone, Provider provider)
    {
      return Feed;
    }
  }
Exception message: 'ReferenceOwnershipBuilder' does not contain a definition for 'HasDiscriminator' and the best extension method overload 'RelationalEntityTypeBuilderExtensions.HasDiscriminator<string>(EntityTypeBuilder, string)' requires a receiver of type 'EntityTypeBuilder'
16>Migrations/20190228155115_UpdateDateTimeOffsetToBeNullable.Designer.cs(1265,29): Error CS1929 : 'ReferenceOwnershipBuilder' does not contain a definition for 'HasDiscriminator' and the best extension method overload 'RelationalEntityTypeBuilderExtensions.HasDiscriminator<string>(EntityTypeBuilder, string)' requires a receiver of type 'EntityTypeBuilder'
Stack trace: None

Steps to reproduce

protected override void OnModelCreating(ModelBuilder builder)
    {
      base.OnModelCreating(builder);
      
      builder.Entity<TimeZone>().OwnsOne(x => x.Feed)
          .OnDelete(DeleteBehavior.Cascade);

      builder.Entity<DirectFeedSetting>();
      builder.Entity<ProviderFeedSetting>();
};
    }

Further technical details

Calling .Owned instead of .Entity for the 2 sub-classes causes the base type to not be picked up, and throws an error when generating migrations. Mapping FeedSetting to its own table will also throw the same compilation problem

EF Core version: 2.2.0-rtm-35687
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Ubuntu 16.10
IDE: Visual Studio Code 1.31.1/Rider 2018.3

May be similar to #13945 and #9148, however, would like to be able to do this. We have currently added in a custom extension method to allow it compile, code works as expected when running.

@chris-stormideas
Copy link
Author

Actually, this might be covered by #9630, didn't spot this before I raised this

@ajcvickers
Copy link
Contributor

Duplicate of #9630

@ajcvickers ajcvickers marked this as a duplicate of #9630 Feb 28, 2019
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants