0
I saw in an MS link that it is possible to create a partial class and a Metadata class to include Dataannotations in properties created by the Entity Framework (database first). Well, I did as it is in the example, but the application has an error:
The type of metadata associated with the type 'Context.CONTENTS' contains the following properties or unknown fields: CONTENTS. Check that the names of these members match the names of the properties in the main type.
I will send you 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 doesn’t work.
CONTENT.CONTENT ??? or only CONTENTS instead of CONTENT see error
– Marco Souza
Content is a list of contents that have the content in question as "parent". The entity name is CONTENT.
– Claudio Neto