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

Add Code First API to configure the discriminator column #2800

Merged
merged 1 commit into from
Aug 13, 2015

Conversation

AndriySvyryd
Copy link
Member

Add API for setting annotations on internal builders that returns success status

daisy.Relational().DiscriminatorValue = PlantGenus.Daisy;
modelBuilder.Entity<Plant>().Discriminator(p => p.Genus)
.HasValue(typeof(Rose), PlantGenus.Rose)
.HasValue(typeof(Daisy), PlantGenus.Daisy);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rowanmiller What do you think about this API?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. A few things spring to mind:

  1. No generics for the derived types.
  2. Feels more natural to configure the derived via Entity() but I guess you came up with this to keep strong typing.

E.g.

modelBuilder.Entity<Plant>().DiscriminatorProperty(p => p.Genus)
modelBuilder.Entity<Rose>().DiscriminatorValue(PlantGenus.Rose)

cc @divega, @bricelam, @ajcvickers

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anpete

  1. There's no point for specifying derived type via a generic argument, since there's nothing to deduce it from and there's no API downstream that would benefit from it
  2. Yes, I prefer the value to be strongly typed in the API. You can still add the value from the derived type:
modelBuilder.Entity<Rose>().Discriminator().HasValue(typeof(Rose), PlantGenus.Rose)

We could add sugar for this to make it look like yours

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndriySvyryd

  1. We also do it just because it just looks better and is easier to type. E.g. modelBuilder.Ignore<Foo>();
  2. Yeah, your example looks kinda strange because its WET :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to discuss this all up tomorrow in the design meeting.

FWIW, I don't like the API a lot at first glance but I would like to make sure I understand what we are trying to achieve.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll discuss this in the API review. It wouldn't affect the bulk of the commit though.

// TODO: remove this when the discriminator convention is added
modelBuilder.Entity<Animal>().Discriminator()
.HasValue(typeof(Eagle), "Eagle")
.HasValue(typeof(Kiwi), "Kiwi");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we need the parameterless overload. Since the user will specify the values perhaps we should force them to specify the type explicitly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this for the case where we introduce a shadow prop?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there is another one that takes the shadow prop name and is generic on the type? If so, then this no-arg one could go away.

@AndriySvyryd AndriySvyryd force-pushed the Discriminator branch 2 times, most recently from 1bfacda to 9bd80dd Compare August 12, 2015 16:44
@@ -167,6 +165,8 @@ private bool InheritsFrom(EntityType entityType)
return false;
}

public virtual EntityType RootType() => (EntityType)((IEntityType)this).RootType();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unfortunate but can't think of an easy solution.

@anpete
Copy link
Contributor

anpete commented Aug 13, 2015

:shipit:

Add API for setting annotations on internal builders that returns success status

Part of #1704
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants