I know this is an old question, but here is the solution I used for such cases. This is useful when you have automatically generated classes that you want to decorate with attributes. Let them say that this is an automatically generated class:
public partial class UserProfile { public int UserId { get; set; } public string UserName { get; set; } public string Firstname { get; set; } public string Lastname { get; set; } }
And let, say, I would like to add an attribute to indicate that UserId is the key. Then I would create a partial class in another file, for example:
[Table("UserProfile")] [MetadataType(typeof(UserProfileMetadata))] public partial class UserProfile { internal sealed class UserProfileMetadata { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int UserId { get; set; } } }
Jean-FranΓ§ois Beauchamp Oct. 19 '13 at 4:33 on 2013-10-19 04:33
source share