I saw in an MS link that it is possible to create a partial and a Metadata class to include DataAnnotations in properties created by the Entity Framework (database first). Well, I did as the example, but the application has an error:
The metadata type associated with type 'Context.CONTEUDO' contains the following unknown properties or fields: CONTENT. Make sure the names of these members match the names of the properties in the parent type.
I will send the code of the 3 classes (generated by EF, metadata and partial):
// EF scaffolding
namespace Context
{
using System;
using System.Collections.Generic;
public partial class CONTEUDO
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public CONTEUDO()
{
this.CONTEUDOS = new HashSet<CONTEUDO>();
this.CONTEUDO_ANEXO = new HashSet<CONTEUDO_ANEXO>();
this.CONTEUDO_PERMISSOES = new HashSet<CONTEUDO_PERMISSOES>();
}
public int COD_CONTEUDO { get; set; }
public Nullable<int> COD_CONTEUDO_PAI { get; set; }
public int COD_EBOOK { get; set; }
public string TITULO { get; set; }
public string TEXTO { get; set; }
public Nullable<System.DateTime> CRIADO_EM { get; set; }
public int CRIADO_POR { get; set; }
public System.Guid UNIQUE_ID { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<CONTEUDO> CONTEUDOS { get; set; }
public virtual CONTEUDO CONTEUDO_PAI { get; set; }
public virtual USUARIO USUARIO { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<CONTEUDO_ANEXO> CONTEUDO_ANEXO { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<CONTEUDO_PERMISSOES> CONTEUDO_PERMISSOES { get; set; }
public virtual EBOOK EBOOK { get; set; }
}
}
// Metadata
namespace Context
{
public class ConteudoMetadata
{
[Required]
[Range(1, 999999)]
[Display(Name = "Ebook")]
public int COD_EBOOK;
[Required]
[Display(Name = "Título")]
public string TITULO;
[Required]
[Display(Name = "Conteúdo")]
public string CONTEUDO;
}
}
// Partial com MetadataType attribute
namespace Context
{
[MetadataType(typeof(ConteudoMetadata))]
public partial class CONTEUDO
{
}
}
It's all in the same namespace, so there's no problem, but it does not work.