1

I have the following table definition:

public partial class ClientClassification
{
    [Key, Column(Order = 0)]
    public long ClientId { get; set; }

    [Key, Column(Order = 1)]
    public ClientClassificationEnum ClientClassificationType { get; set; }

    [ForeignKey("ClientId")]
    public virtual Client Client { get; set; }
}

ClientId is a foreign key into the Client table. This is a many to 1 relationship (a client can have many classifications). Is there any way I can omit the Client navigation property but still declare this foreign key relationship? So something like:

public partial class ClientClassification
{
    [Key, Column(Order = 0)]
    [ForeignKey("Client.ClientId")]
    public long ClientId { get; set; }

    [Key, Column(Order = 1)]
    public ClientClassificationEnum ClientClassificationType { get; set; }
}
1
  • Anybody got any thoughts?
    – TheEdge
    Apr 1, 2014 at 3:17

1 Answer 1

0

Since there will be no relationship between "classes" and still you want to create the relationship on the dtaabase, I would be using a migration script to do it (and no annotations on the class).

If you would still like to have the annotation on the class (for a reason that I can't imagine right now) you could then declare a protected Client attribute (this way you would be declaring the Client navigation property but it wouldn't be accessible for anyone but inherited classes).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.