First, is there a way to tell EF 4.1 that a column needs to be unique by using either data annotations or the fluent API?
Second, regarding navigation properties, I have have 2 classes Document and User. In the document class I have a property for the OwnerId (UserId) and a property for Owner (User). How do I tell EF 4.1 that the OwnerId is really UserId and Owner is a navigation property back to User?
The Document Class:
public abstract class Document: BaseEntity
{
public bool IsActive { get; set; }
public string Description { get; set; }
//The UserId
public Guid OwnerId { get; set; }
//The User
public User Owner { get; set; }
}
Entity framework doesn’t support unique keys at all so the answer to your first question is no.
OwnerIdshould be recognized as foreign key forOwnerautomatically unless you map to existing database where the foreign key is named differently. In such case you can use for example:Foreign key data annotation is probably not needed but you can use it to explicitly pair your FK property with navigation property.
In fluent mapping you can use: