none
Metadata Type does not work in EF RRS feed

  • Question

  • Once I again I have looked at previous threads dating aroune 2010 - 2008 so have absolutely no relevance today.

    The Data Annotations that I am applying MetadataType "buddy" class are not being applied.  I know I could apply this example I am using in the view; but, I want to know why what is advertised as suppose to work doesn't.

    Here is the buddy class:

    namespace PhotographerAssignmentSystem.Domain.Entities
    {
    
        [MetadataType(typeof(EventMetadata))]
        public partial class Event
        {
    
        }
    
        public class EventMetadata
        {
            [DisplayFormat(DataFormatString = "{0:d}")]
            public DateTime EventDT { get; set; }
        }
    
    }
    
    

    Here is the Class:  Notice that namespace and class name match

    namespace PhotographerAssignmentSystem.Domain.Entities
    {    
    
        public partial class Event
        {
            public string LabOrderNbr { get; set; }
            public DateTime EventDT { get; set; }
            public string Campus { get; set; }
            public string Organization { get; set; }
    
            public virtual List<PhotographerAssignment> Assignments { get; set; }
        }
    
    }

    Here is the dbContext classs:

    using System.Text;
    using System.Data.Entity;
    using PhotographerAssignmentSystem.Domain.Entities;
    using System.Data.Entity.ModelConfiguration.Conventions;
    
    namespace PhotographerAssignmentSystem.Domain.Concrete
    {
        public class EFDbContext : DbContext
        {
            public DbSet<Photographer> Photographers { get; set; }
            public DbSet<PhotographerAssignment> PhotographerAssignments { get; set; }
            public DbSet<PhotographerAssignmentStatus> PhotographerAssignmentStatuses { get; set; }
            public DbSet<Event> Events { get; set; }
            public DbSet<PhotoRole> PhotoRoles { get; set; }
    
            public EFDbContext(): base() // since I am not specifying a connection string, defaults to connection string of same name in web.config
            {
                Database.SetInitializer<EFDbContext>(null);
            }
    
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
                modelBuilder.Configurations.Add(new PhotographerConfiguration());
                modelBuilder.Configurations.Add(new PhotographerAssignmentConfiguration());
                modelBuilder.Configurations.Add(new PhotographerAssignmentStatusConfiguration());
                modelBuilder.Configurations.Add(new EventConfiguration());
                modelBuilder.Configurations.Add(new PhotoRoleConfiguration());
    
            }
        }
    }


    WhiskeyRomeoLima

    Friday, July 13, 2012 6:38 PM

Answers

All replies