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

Cannot have a ForeignKey use same member as Identity #1226

Closed
barclayadam opened this issue Mar 14, 2019 · 4 comments
Closed

Cannot have a ForeignKey use same member as Identity #1226

barclayadam opened this issue Mar 14, 2019 · 4 comments

Comments

@barclayadam
Copy link
Contributor

It is not possible to have an entity that has a member that is used for both its Id and as a foreign key to another entity. For example:

For<FooExtra>()
    .IdStrategy(new NoOpIdGeneration())
    .Identity(x => x.FooId)
    .ForeignKey<Foo>(x => x.FoodId)
    .MultiTenanted();

The intention is to have a one-to-one relationship between parent Foo and it's child FooExtra.

This fails on the schema generation as no additional column is created for this foreign key.

Should this be supported, or should this throw earlier to identify this as being unsupported?

@barclayadam barclayadam changed the title Cannot have a ForiegnKey use same member as Identity Cannot have a ForeignKey use same member as Identity Mar 14, 2019
@jeremydmiller
Copy link
Member

@barclayadam Before I put much into fixing this, is this really necessary? If it's really one to one in the document, why not just have one single document type?

@barclayadam
Copy link
Contributor Author

barclayadam commented May 9, 2019

@jeremydmiller Good question. Strictly speaking, I'd say no, it's possible to work around it. Our use case for this is two-fold:

  1. We are migrating legacy code from Azure Table store and keeping them separate simplifies that path

  2. The entities change on a completely separate change axis, the parent is often only ever created and then not changed, the child is changed often. We have things that respond to changes in entities, so it is useful to keep the changes separate. We also have this the other way around, with supplementary data being updated often but we do not want that being "part of" the parent entity.

If this does not go through as an enhancement, could it be changed to throw an exception? Tracking down the root cause with only a SQL error is tricky. I cannot remember the exact message but it was non-obvious why it was failing

@mysticmind
Copy link
Member

This issue looks to be fixed and working fine, will add a unit test for this.

@mysticmind
Copy link
Member

Unit test passed, closing this.

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

4 participants