Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
225
Data Anotations - database first
posted

Hi, 

 we are using EF with database first method. When I create new view model, data annotation works fine. But when I put my data annotation in to partial class I was not able to make them work.

Works:

public class TenantViewModel
{

[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }

[Required(ErrorMessageResourceName = "msg0004", ErrorMessageResourceType = typeof(Resources.Messages))]
[StringLength(Defaults.TenantNameMaxLength, ErrorMessageResourceName = "msg0005", ErrorMessageResourceType = typeof(Resources.Messages))]
[Display(Name = "name", ResourceType = typeof(Resources.Translations))]
public string Name { get; set; }

[Required(ErrorMessageResourceName = "msg0004", ErrorMessageResourceType = typeof(Resources.Messages))]
[StringLength(Defaults.TenantSchemaNameMaxLength, ErrorMessageResourceName = "msg0005", ErrorMessageResourceType = typeof(Resources.Messages))]
[Display(Name = "schemaName", ResourceType = typeof(Resources.Translations))]
public string SchemaName { get; set; }

}

Do not work:

[MetadataType(typeof(Tenant.TenantMetadata))]

public partial class Tenant

{

private sealed class TenantMetadata

{

[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }

[Required(ErrorMessageResourceName = "msg0004", ErrorMessageResourceType = typeof(Resources.Messages))]
[StringLength(Defaults.TenantNameMaxLength, ErrorMessageResourceName = "msg0005", ErrorMessageResourceType = typeof(Resources.Messages))]
[Display(Name = "name", ResourceType = typeof(Resources.Translations))]
public string Name { get; set; }

[Required(ErrorMessageResourceName = "msg0004", ErrorMessageResourceType = typeof(Resources.Messages))]
[StringLength(Defaults.TenantSchemaNameMaxLength, ErrorMessageResourceName = "msg0005", ErrorMessageResourceType = typeof(Resources.Messages))]
[Display(Name = "schemaName", ResourceType = typeof(Resources.Translations))]
public string SchemaName { get; set; }

}

}

Any idea why? Thanks.

Parents Reply Children
No Data