user5319326
user5319326

Reputation:

mvc 4 - c# - Entity Framework - Metadata using edmx file

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).

Upvotes: 2

Views: 848

Answers (1)

user3812703
user3812703

Reputation:

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
     }

}

Upvotes: 1

Related Questions