EF Context explicit interface implementation, raises an exception

EF DBContext

The following exception:

An unhandled exception of type 'System.Data.Entity.ModelConfiguration.ModelValidationException' occurred in EntityFramework.dll

Additional information: One or more validation errors were detected during model generation:
MetaDAL.POCOContext.IMetaContext.MAssemblyFiles: Name: The specified name is not allowed: 'MetaDAL.POCOContext.IMetaContext.MAssemblyFiles'.

MetaDAL.POCOContext.IMetaContext.MAssemblyFileObjects: Name: The specified name is not allowed: 'MetaDAL.POCOContext.IMetaContext.MAssemblyFileObjects'.

MetaDAL.POCOContext.IMetaContext.MetaObjects: Name: The specified name is not allowed: 'MetaDAL.POCOContext.IMetaContext.MetaObjects'.

MetaDAL.POCOContext.IMetaContext.MAssemblyFilePropertyValues: Name: The specified name is not allowed: 'MetaDAL.POCOContext.IMetaContext.MAssemblyFilePropertyValues'.

MetaDAL.POCOContext.IMetaContext.MAssemblyFileProperties: Name: The specified name is not allowed: 'MetaDAL.POCOContext.IMetaContext.MAssemblyFileProperties'.

MetaDAL.POCOContext.IMetaContext.MAssemblyFolders: Name: The specified name is not allowed: 'MetaDAL.POCOContext.IMetaContext.MAssemblyFolders'.

An unhandled exception of type 'System.ArgumentNullException' occurred in System.Core.dll  Value cannot be null.


Made me wonder for days, for a solution, i searched a lot in the net, but nothing came to solve it.

and while testing a lot of things, i tested taking off the explicit interface implementation

The problematic context class “MetaContext”:

public partial class MetaContext : DbContext, IMetaContext
    DbSet<AppOptionTree> IMetaContext.AppOptionTrees { get; set; }
    DbSet<MAssembly> IMetaContext.MAssemblies { get; set; }
    DbSet<MAssemblyFile> IMetaContext.MAssemblyFiles { get; set; }
    DbSet<MAssemblyFileObject> IMetaContext.MAssemblyFileObjects { get; set; }
    DbSet<MAssemblyFileProperty> IMetaContext.MAssemblyFileProperties { get; set; }
    DbSet<MAssemblyFilePropertyValue> IMetaContext.MAssemblyFilePropertyValues { get; set; }
    DbSet<MAssemblyFolder> IMetaContext.MAssemblyFolders { get; set; }
    DbSet<MetaObject> IMetaContext.MetaObjects { get; set; }


The interface:

public interface IMetaContext : IDisposable
    DbSet<AppOptionTree> AppOptionTrees { get; set; }
    DbSet<MAssembly> MAssemblies { get; set; }
    DbSet<MAssemblyFile> MAssemblyFiles { get; set; }
    DbSet<MAssemblyFileObject> MAssemblyFileObjects { get; set; }
    DbSet<MAssemblyFileProperty> MAssemblyFileProperties { get; set; }
    DbSet<MAssemblyFilePropertyValue> MAssemblyFilePropertyValues { get; set; }
    DbSet<MAssemblyFolder> MAssemblyFolders { get; set; }
    DbSet<MetaObject> MetaObjects { get; set; }





When it was implementing the interface explicitly, it made the properties belong to the interface, and the “MetaContext” class does not have any properties, so the Base “DbContext” could not find any properties, hence the Error:

“Name: The specified name is not allowed: ‘MetaDAL.POCOContext.IMetaContext.MAssemblyFiles’.”, it says it can’t see, or can’t find the property “MAssemblyFiles”


The solution:

The solution was just to take off the “IMetaContext.” that makes the property implements the interface explicitly, and adding the “public” access modifier to the properties, and this will make them properties to the Context class and implicitly implement the interface “IMetaContext”.

public partial class MetaContext : DbContext, IMetaContext
    public DbSet<AppOptionTree> AppOptionTrees { get; set; }
    public DbSet<MAssembly> MAssemblies { get; set; }
    public DbSet<MAssemblyFile> MAssemblyFiles { get; set; }
    public DbSet<MAssemblyFileObject> MAssemblyFileObjects { get; set; }
    public DbSet<MAssemblyFileProperty> MAssemblyFileProperties { get; set; }
    public DbSet<MAssemblyFilePropertyValue> MAssemblyFilePropertyValues { get; set; }
    public DbSet<MAssemblyFolder> MAssemblyFolders { get; set; }
    public DbSet<MetaObject> MetaObjects { get; set; }




About Reader Man حسين ناجي الصفافير

حسين ناجي الصفافير Hussain Naji Al-Safafeer Info: https://readerman1.wordpress.com/aboutme
This entry was posted in EntityFramework and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s