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

Owned Type as Primary Key? #10682

Closed
hikalkan opened this issue Jan 11, 2018 · 2 comments
Closed

Owned Type as Primary Key? #10682

hikalkan opened this issue Jan 11, 2018 · 2 comments

Comments

@hikalkan
Copy link

hikalkan commented Jan 11, 2018

Hi,

Suppose that we have an entity like that:

public class ClientGrantType
{
    public virtual ClientGrantTypeId Id { get; set; } //primary key on the entity

    protected ClientGrantType()
    {

    }

    public ClientGrantType(ClientGrantTypeId id)
    {
        Id = id;
    }
}

And ClientGrantTypeId is defined as:

public class ClientGrantTypeId
{
    public virtual string GrantType { get; protected set; }

    public virtual Guid ClientId { get; protected set; }

    protected ClientGrantTypeId()
    {
            
    }

    public ClientGrantTypeId(Guid clientId, string grantType)
    {
        ClientId = clientId;
        GrantType = grantType;
    }
}

ClientGrantTypeId is owned type of ClientGrantType entity and I want to set ClientGrantTypeId type as Id of ClientGrantType entity.
I expect that ClientGrantType entity has a composite PK in the database (as ClientId, GrantType).

As I see it's not possible to define such a primary key as owned type.

  • Is there a way of it?
  • Is it a good practice and do you consider to allow such a definition in next releases?
@ajcvickers
Copy link
Member

We discussed this in triage and decided that this does not fit the conceptual model for owned types, since the identity of the owned type is handled by the parent type, but it in this case the child type has the identity properties. However, it could be supported as part of #9906, and that seems like a much better fit conceptually, so closing this issue and adding a note to consider when implementing #9906.

@hikalkan
Copy link
Author

Thank you @ajcvickers for your explanation and consideration.

@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