David
David

Reputation: 3609

Entity Framework 5.0 Complex Types

I am trying to use a complex type as a key on an entity, however I can't get it to work and not sure if this is just a limitation of the version I am using. I am sure that I have seen it done somewhere.

Can a complex type be used as an key in Entity Framework 5.0??

If so how can this be done??

    public class Identity : IIdentity
{
    public string Id { get; protected set; }

    public Identity()
    {
        Id = Guid.NewGuid().ToString();
    }

    public Identity(string id)
    {

    }
}

    public class ReviewId : Identity
{
    public ReviewId(string id): base(id)
    {
    }

    public ReviewId()
    {
    }
}

    public class Review
{
    public ReviewId ReviewId { get; set; }
}

Entity Framework complains about using ReviewId as a key.

Upvotes: 0

Views: 75

Answers (1)

Pawel
Pawel

Reputation: 31620

EF does not support ComplexType keys.

Upvotes: 1

Related Questions