2

I'm using Entity Framework edmx. When I update the edmx I lose my metadata.How do you create and use metadata properties (that are not real fields).

1
  • Use view models, apply your attributes to the view model properties and map between you view model and data model. Commented Sep 10, 2015 at 2:30

1 Answer 1

1

Create a Metadata folder in the project where is the edmx. Create a class with the name of your entity as bellow: And within the same file create another class with the name of your entity with the "metadata" extension (MyEntityMetadata).

namespace MyNameSpace.DataAccess //You need to use the same namespace of edmx entities files
{
    [MetadataType(typeof(MyEntityMetaData))]
    public partial class MyEntity //This is possible because entities files using partial class
    {
        [NotMapped] //System.ComponentModel.DataAnnotations.Schema
        public int MyProperty { get; set; }


       //more properties...
     }

    public class UsuarioMetaData
    {
        [Display(ResourceType = typeof(Resources.Global), Name = "MyFieldLabel")]
        public int MyField { get; set; }

       //More fields
     }

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.