Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net MapInheritedProperties()未映射继承的外键属性_.net_Entity Framework_Entity Framework 5 - Fatal编程技术网

.net MapInheritedProperties()未映射继承的外键属性

.net MapInheritedProperties()未映射继承的外键属性,.net,entity-framework,entity-framework-5,.net,Entity Framework,Entity Framework 5,这是我的实体类: public abstract class Entity: IEntity { public Guid? Id { get; set; } public bool IsDead { get; set; } public DateTime Created { get; set; } public DateTime Modified { get; set; } public ICollection<EntityAccess>

这是我的实体类:

public abstract class Entity: IEntity
{
    public Guid? Id { get; set; }    
    public bool IsDead { get; set; }
    public DateTime Created { get; set; }
    public DateTime Modified { get; set; }
    public ICollection<EntityAccess> AccessList { get; set; }
    public ICollection<Message> Discussion { get; set; }
    public User Owner { get; set; }
}
EF创建数据库后,发生了一些非常奇怪的事情。从实体继承的属性确实映射到每个表,除了所有者属性。与其他继承属性不同,所有者未映射。怎么解释呢

附加信息:我的实体是简单的POCO对象,没有注释,没有构造函数,什么都没有。例如,以下是用户实体:

public class User : RuntimeEntity
{
    public string Email { get; set; }
    public ICollection<UserGroup> Groups { get; set; }
    public byte[] Password { get; set; }
    public ICollection<Membership> Memberships { get; set; }
}
公共类用户:RuntimeEntity
{
公共字符串电子邮件{get;set;}
公共ICollection组{get;set;}
公共字节[]密码{get;set;}
公共ICollection成员身份{get;set;}
}
编辑:

由于此问题仍然存在,以下是完整的模型:

namespace ConSol.Templex.Data.Entities
{
    public abstract class Association : IEntity
    {
        public Guid? Id { get; set; }
        [NotMapped]
        public virtual RuntimeEntity Entity1 { get; set; }
        [NotMapped]
        public virtual RuntimeEntity Entity2 { get; set; }
    }

public class Attachment : RuntimeEntity
    {
        public AttachmentValidity Validity { get; set; }
        public ICollection<Blob> Versions { get; set; }
        public Profile Profile { get; set; }

    #region Computed properties
        public string Name
        {   
            get 
            {
                    return this.Versions.Last().Name;
            }
        }
        #endregion
    }

public enum AttachmentValidity
    {
        Unverified,
        Verified,
        WorkInProgress
    }

public class Blob : RuntimeEntity
    {
        public string Name { get; set; }
        public byte[] Data { get; set; }
        public Attachment Attachment { get; set; }
        public WorkLog WorkLog { get; set; }
    }

public class EntityAccess : Association
    {
        #region Association implementation
        public override RuntimeEntity Entity1 { get { return this.Entity; } }
        public override RuntimeEntity Entity2
        {
            get
            {
                return this.UserGroup ?? this.User as RuntimeEntity;
            }
            set
            {
                if (value is User) this.User = (User)value; else this.UserGroup = (UserGroup)value;
            }
        }
        #endregion

    public RuntimeEntity Entity { get; set; }
        public UserGroup UserGroup { get; set; }
        public User User { get; set; }
    }
}
?
    public interface IEntity
    {
    }
}
?
    public abstract class MasterEntity : IEntity
    {
        public string Code { get; set; }
        public string Name { get; set; }
    }

public class Membership : Association
    {
        #region Association implementation
        public override RuntimeEntity Entity1 { get { return this.User; } }
        public override RuntimeEntity Entity2 { get { return this.UserGroup; } }
        #endregion

    public User User { get; set; }
        public UserGroup UserGroup { get; set; }
        public bool IsAdmin { get; set; }
    }

public class Message : RuntimeEntity
    {
        public string Text { get; set; }
        public RuntimeEntity RuntimeEntity { get; set; }

    #region Computed properties
        public User Author
        {
            get
            {
                return this.Owner;
            }
        }
        #endregion
    }

public class Parameter : RuntimeEntity
    {
        public string Code { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }

    public Worker Worker
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }
    }

public class ParameterValue : ConSol.Templex.Data.Entities.RuntimeEntity
    {
        public string Value { get; set; }
        public Parameter Parameter { get; set; }
        public Worker Worker { get; set; }

    public Profile Profile
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }
    }

public class ProductStatus : RuntimeEntity
    {
        public Profile Profile { get; set; }
        public Guid ProductId { get; set; }
        public ExportStatus Status { get; set; }
        public WorkLog WorkLog { get; set; }

    public enum ExportStatus
        {
            Exported,
            Imported,
            Error
        }
    }

public class Profile : RuntimeEntity
    {
        public string Name { get; set; }
        public ICollection<Attachment> Attachments { get; set; }
        public ICollection<ParameterValue> Parameters { get; set; }
        public ICollection<WorkLog> WorkLogs { get; set; }
        public Worker Exporter { get; set; }
        public Worker Importer { get; set; }
        public TimeSpan? Frequency { get; set; }
        public DateTime FirstRun { get; set; }
        public string Destination { get; set; }
        public ICollection<ProductStatus> ProductQueue { get; set; }
    }
}
?
    public abstract class RuntimeEntity : IEntity, ISoftDeletable
    {
        public Guid? Id { get; set; }

    public bool IsDead { get; set; }
        public DateTime Created { get; set; }
        public DateTime Modified { get; set; }
        //public ICollection<EntityAccess> AccessList { get; set; }
        public ICollection<Message> Discussion { get; set; }
        public User Owner { get; set; }

    /// <summary>
        /// This defines the default filter for all entities
        /// </summary>
        public static Expression<Func<TIn,bool>> DefaultFilterFor<TIn>(User user)
            where TIn : RuntimeEntity
        {
            return x => true;
        }

    /// <summary>
        /// This defines an optional filter to be used most of the time
        /// </summary>
        public static Expression<Func<TIn, bool>> AdditionalFilterFor<TIn>(User user)
            where TIn : RuntimeEntity
        {
            return x => !x.IsDead;
        }
    }

public class Schedule : RuntimeEntity
    {
        public DateTime Start { get; set; }
        public TimeSpan Frequency { get; set; }
    }

public class User : RuntimeEntity
    {
        public string Email { get; set; }
        public ICollection<UserGroup> Groups { get; set; }
        public byte[] Password { get; set; }
        public ICollection<Membership> Memberships { get; set; }
    }

public class UserGroup : RuntimeEntity
    {
        public string CustomerId { get; set; }
        public string Name { get; set; }
        public bool IsSuperGroup { get; set; }
        public ICollection<Membership> Memberships { get; set; }

    #region Computed properties
        public IEnumerable<User> Admins
        {
            get
            {
                return this.Memberships.Where(x => x.IsAdmin).Select(x => x.User);
            }
        }
        #endregion
    }

public class Worker : RuntimeEntity
    {
        public ICollection<Parameter> Parameters { get; set; }
        public string AssemblyName { get; set; }
        public byte[] Assembly { get; set; }
        public WorkType Work { get; set; }

    public enum WorkType
        {
            Import,
            Export
        }
    }

public class WorkerMessage : RuntimeEntity
    {
        public string Message { get; set; }
        public MessageType Outcome { get; set; }
        public WorkLog WorkLog { get; set; }

    public enum MessageType
        {
            Information,
            Warning,
            Error
        }
    }

public class WorkLog : RuntimeEntity
    {
        public DateTime End { get; set; }
        public Profile Profile { get; set; }
        public Worker Worker { get; set; }
        public WorkResult Result { get; set; }
        public ICollection<Blob> Files { get; set; }
        public ICollection<WorkerMessage> Report { get; set; }
    }

    public enum WorkResult
        {
            Success,
            Warning,
            Failure
        }
    }
}
名称空间ConSol.Templex.Data.Entities
{
公共抽象类关联:通用性
{
公共Guid?Id{get;set;}
[未映射]
公共虚拟运行时实体Entity1{get;set;}
[未映射]
公共虚拟运行时实体Entity2{get;set;}
}
公共类附件:RuntimeEntity
{
公共附件有效性{get;set;}
公共ICollection版本{get;set;}
公共配置文件{get;set;}
#区域计算属性
公共字符串名
{   
得到
{
返回此.Versions.Last().Name;
}
}
#端区
}
公共枚举附件有效性
{
未经证实,
已证实的
工作进度
}
公共类Blob:RuntimeEntity
{
公共字符串名称{get;set;}
公共字节[]数据{get;set;}
公共附件{get;set;}
公共工作日志工作日志{get;set;}
}
公共类EntityAccess:关联
{
#区域关联实现
公共重写RuntimeEntity Entity1{get{返回this.Entity;}}
公共重写RuntimeEntity Entity2
{
得到
{
将this.UserGroup??this.User作为RuntimeEntity返回;
}
设置
{
如果(值为User)this.User=(User)值;否则this.UserGroup=(UserGroup)值;
}
}
#端区
公共运行时实体{get;set;}
公共用户组用户组{get;set;}
公共用户{get;set;}
}
}
?
公共界面的开放性
{
}
}
?
公共抽象类主实体:通用性
{
公共字符串代码{get;set;}
公共字符串名称{get;set;}
}
公共班级成员:协会
{
#区域关联实现
公共重写RuntimeEntity Entity1{get{返回this.User;}}
公共重写RuntimeEntity Entity2{get{返回this.UserGroup;}}
#端区
公共用户{get;set;}
公共用户组用户组{get;set;}
公共bool IsAdmin{get;set;}
}
公共类消息:RuntimeEntity
{
公共字符串文本{get;set;}
公共运行时实体运行时实体{get;set;}
#区域计算属性
公共用户作者
{
得到
{
归还这个。所有者;
}
}
#端区
}
公共类参数:RuntimeEntity
{
公共字符串代码{get;set;}
公共字符串名称{get;set;}
公共字符串说明{get;set;}
公务员
{
得到
{
抛出新系统。NotImplementedException();
}
设置
{
}
}
}
公共类参数值:ConSol.Templex.Data.Entities.RuntimeEntity
{
公共字符串值{get;set;}
公共参数{get;set;}
公共工作者{get;set;}
公众简介
{
得到
{
抛出新系统。NotImplementedException();
}
设置
{
}
}
}
公共类ProductStatus:RuntimeEntity
{
公共配置文件{get;set;}
公共Guid ProductId{get;set;}
公共导出状态状态{get;set;}
公共工作日志工作日志{get;set;}
公共枚举导出状态
{
出口,,
进口,,
错误
}
}
公共类配置文件:RuntimeEntity
{
公共字符串名称{get;set;}
公共ICollection附件{get;set;}
公共ICollection参数{get;set;}
公共ICollection工作日志{get;set;}
公共工作者导出器{get;set;}
公共工作者导入程序{get;set;}
公共时间跨度?频率{get;set;}
public DateTime FirstRun{get;set;}
公共字符串目标{get;set;}
公共ICollection ProductQueue{get;set;}
}
}
?
公共抽象类运行时实体:IEntity,ISoftDeletable
{
公共Guid?Id{get;set;}
公共bool IsDead{get;set;}
已创建公共日期时间{get;set;}
修改的公共日期时间{get;set;}
//公共ICollection访问列表{get;set;}
公共ICollection讨论{get;set;}
公共用户所有者{get;set;}
/// 
///这将为所有实体定义默认过滤器
/// 
公共静态表达式DefaultFilterFor(用户)
其中TIn:RuntimeEntity
{
返回x=>true;
}
/// 
///这定义了一个可供大多数时间使用的可选过滤器
/// 
公共静态表达式附加筛选器(用户)
其中TIn:RuntimeEntity
{
返回x=>!x.ishead;
}
}
公共类Sche
namespace ConSol.Templex.Data.Entities
{
    public abstract class Association : IEntity
    {
        public Guid? Id { get; set; }
        [NotMapped]
        public virtual RuntimeEntity Entity1 { get; set; }
        [NotMapped]
        public virtual RuntimeEntity Entity2 { get; set; }
    }

public class Attachment : RuntimeEntity
    {
        public AttachmentValidity Validity { get; set; }
        public ICollection<Blob> Versions { get; set; }
        public Profile Profile { get; set; }

    #region Computed properties
        public string Name
        {   
            get 
            {
                    return this.Versions.Last().Name;
            }
        }
        #endregion
    }

public enum AttachmentValidity
    {
        Unverified,
        Verified,
        WorkInProgress
    }

public class Blob : RuntimeEntity
    {
        public string Name { get; set; }
        public byte[] Data { get; set; }
        public Attachment Attachment { get; set; }
        public WorkLog WorkLog { get; set; }
    }

public class EntityAccess : Association
    {
        #region Association implementation
        public override RuntimeEntity Entity1 { get { return this.Entity; } }
        public override RuntimeEntity Entity2
        {
            get
            {
                return this.UserGroup ?? this.User as RuntimeEntity;
            }
            set
            {
                if (value is User) this.User = (User)value; else this.UserGroup = (UserGroup)value;
            }
        }
        #endregion

    public RuntimeEntity Entity { get; set; }
        public UserGroup UserGroup { get; set; }
        public User User { get; set; }
    }
}
?
    public interface IEntity
    {
    }
}
?
    public abstract class MasterEntity : IEntity
    {
        public string Code { get; set; }
        public string Name { get; set; }
    }

public class Membership : Association
    {
        #region Association implementation
        public override RuntimeEntity Entity1 { get { return this.User; } }
        public override RuntimeEntity Entity2 { get { return this.UserGroup; } }
        #endregion

    public User User { get; set; }
        public UserGroup UserGroup { get; set; }
        public bool IsAdmin { get; set; }
    }

public class Message : RuntimeEntity
    {
        public string Text { get; set; }
        public RuntimeEntity RuntimeEntity { get; set; }

    #region Computed properties
        public User Author
        {
            get
            {
                return this.Owner;
            }
        }
        #endregion
    }

public class Parameter : RuntimeEntity
    {
        public string Code { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }

    public Worker Worker
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }
    }

public class ParameterValue : ConSol.Templex.Data.Entities.RuntimeEntity
    {
        public string Value { get; set; }
        public Parameter Parameter { get; set; }
        public Worker Worker { get; set; }

    public Profile Profile
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }
    }

public class ProductStatus : RuntimeEntity
    {
        public Profile Profile { get; set; }
        public Guid ProductId { get; set; }
        public ExportStatus Status { get; set; }
        public WorkLog WorkLog { get; set; }

    public enum ExportStatus
        {
            Exported,
            Imported,
            Error
        }
    }

public class Profile : RuntimeEntity
    {
        public string Name { get; set; }
        public ICollection<Attachment> Attachments { get; set; }
        public ICollection<ParameterValue> Parameters { get; set; }
        public ICollection<WorkLog> WorkLogs { get; set; }
        public Worker Exporter { get; set; }
        public Worker Importer { get; set; }
        public TimeSpan? Frequency { get; set; }
        public DateTime FirstRun { get; set; }
        public string Destination { get; set; }
        public ICollection<ProductStatus> ProductQueue { get; set; }
    }
}
?
    public abstract class RuntimeEntity : IEntity, ISoftDeletable
    {
        public Guid? Id { get; set; }

    public bool IsDead { get; set; }
        public DateTime Created { get; set; }
        public DateTime Modified { get; set; }
        //public ICollection<EntityAccess> AccessList { get; set; }
        public ICollection<Message> Discussion { get; set; }
        public User Owner { get; set; }

    /// <summary>
        /// This defines the default filter for all entities
        /// </summary>
        public static Expression<Func<TIn,bool>> DefaultFilterFor<TIn>(User user)
            where TIn : RuntimeEntity
        {
            return x => true;
        }

    /// <summary>
        /// This defines an optional filter to be used most of the time
        /// </summary>
        public static Expression<Func<TIn, bool>> AdditionalFilterFor<TIn>(User user)
            where TIn : RuntimeEntity
        {
            return x => !x.IsDead;
        }
    }

public class Schedule : RuntimeEntity
    {
        public DateTime Start { get; set; }
        public TimeSpan Frequency { get; set; }
    }

public class User : RuntimeEntity
    {
        public string Email { get; set; }
        public ICollection<UserGroup> Groups { get; set; }
        public byte[] Password { get; set; }
        public ICollection<Membership> Memberships { get; set; }
    }

public class UserGroup : RuntimeEntity
    {
        public string CustomerId { get; set; }
        public string Name { get; set; }
        public bool IsSuperGroup { get; set; }
        public ICollection<Membership> Memberships { get; set; }

    #region Computed properties
        public IEnumerable<User> Admins
        {
            get
            {
                return this.Memberships.Where(x => x.IsAdmin).Select(x => x.User);
            }
        }
        #endregion
    }

public class Worker : RuntimeEntity
    {
        public ICollection<Parameter> Parameters { get; set; }
        public string AssemblyName { get; set; }
        public byte[] Assembly { get; set; }
        public WorkType Work { get; set; }

    public enum WorkType
        {
            Import,
            Export
        }
    }

public class WorkerMessage : RuntimeEntity
    {
        public string Message { get; set; }
        public MessageType Outcome { get; set; }
        public WorkLog WorkLog { get; set; }

    public enum MessageType
        {
            Information,
            Warning,
            Error
        }
    }

public class WorkLog : RuntimeEntity
    {
        public DateTime End { get; set; }
        public Profile Profile { get; set; }
        public Worker Worker { get; set; }
        public WorkResult Result { get; set; }
        public ICollection<Blob> Files { get; set; }
        public ICollection<WorkerMessage> Report { get; set; }
    }

    public enum WorkResult
        {
            Success,
            Warning,
            Failure
        }
    }
}
public class TemplexDB : DbContextBase
{
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Attachment>().Map(m =>
        {
            m.MapInheritedProperties();
            m.ToTable("Attachment");
        });
        modelBuilder.Entity<Blob>().Map(m =>
        {
            m.MapInheritedProperties();
            m.ToTable("Blob");
        });
        modelBuilder.Entity<Message>().Map(m =>
        {
            m.MapInheritedProperties();
            m.ToTable("Message");
        });
        modelBuilder.Entity<Parameter>().Map(m =>
        {
            m.MapInheritedProperties();
            m.ToTable("Parameter");
        });
        modelBuilder.Entity<ParameterValue>().Map(m =>
        {
            m.MapInheritedProperties();
            m.ToTable("ParameterValue");
        });
        modelBuilder.Entity<ProductStatus>().Map(m =>
        {
            m.MapInheritedProperties();
            m.ToTable("ProductStatus");
        });
        modelBuilder.Entity<Profile>().Map(m =>
        {
            m.MapInheritedProperties();
            m.ToTable("Profile");
        });
        modelBuilder.Entity<Schedule>().Map(m =>
        {
            m.MapInheritedProperties();
            m.ToTable("Schedule");
        });
        modelBuilder.Entity<User>().Map(m =>
        {
            m.MapInheritedProperties();
            m.ToTable("User");
        });
        modelBuilder.Entity<UserGroup>().Map(m =>
        {
            m.MapInheritedProperties();
            m.ToTable("UserGroup");
        });
        modelBuilder.Entity<Worker>().Map(m =>
        {
            m.MapInheritedProperties();
            m.ToTable("Worker");
        });
        modelBuilder.Entity<WorkerMessage>().Map(m =>
        {
            m.MapInheritedProperties();
            m.ToTable("WorkerMessage");
        });
        modelBuilder.Entity<WorkLog>().Map(m =>
        {
            m.MapInheritedProperties();
            m.ToTable("WorkLog");
        });
        modelBuilder.Entity<EntityAccess>().Map(m =>
        {
            m.MapInheritedProperties();
            m.ToTable("EntityAccess");
        });
        modelBuilder.Entity<Membership>().Map(m =>
        {
            m.MapInheritedProperties();
            m.ToTable("Membership");
        });
    }

public DbSet<Attachment> Attachments { get; set; }
    public DbSet<Blob> Blobs { get; set; }
    public DbSet<Message> Messages { get; set; }
    public DbSet<Parameter> Parameters { get; set; }
    public DbSet<ParameterValue> ParameterValues { get; set; }
    public DbSet<ProductStatus> ProductStatuses { get; set; }
    public DbSet<Profile> Profiles { get; set; }
    public DbSet<Schedule> Schedules { get; set; }
    public DbSet<User> Users { get; set; }
    public DbSet<UserGroup> UserGroups { get; set; }
    public DbSet<Worker> Workers { get; set; }
    public DbSet<WorkerMessage> WorkerMessages { get; set; }
    public DbSet<WorkLog> WorkLogs { get; set; }

// associations
    public DbSet<EntityAccess> EntityAccess { get; set; }
    public DbSet<Membership> Membership { get; set; }
}
   public abstract class Entity 
    {
        public Guid? Id { get; set; }
        public bool IsDead { get; set; }
        public DateTime Created { get; set; }
        public DateTime Modified { get; set; }
        public ICollection<EntityAccess> AccessList { get; set; }
        public ICollection<Message> Discussion { get; set; }
        public User Owner { get; set; }
    }

    public class EntityAccess
    {
        public int Id { get; set; }
    }

    public class Message
    {
        public int Id { get; set; }
    }
    public class Structure : Entity
    {
        public string Property { get; set; }
    }
    public class User
    {
        public int Id { get; set; }
        public string Email { get; set; }
        public ICollection<UserGroup> Groups { get; set; }
        public byte[] Password { get; set; }
        public ICollection<Membership> Memberships { get; set; }
    }

    public class UserGroup
    {
        public int Id { get; set; }
    }

    public class Membership
    {
        public int Id { get; set; }
    }

    public class Model : DbContext
    {
        public DbSet<Structure> Structures { get; set; }
        public DbSet<User> Users { get; set; }
        public DbSet<EntityAccess> EntityAccesses { get; set; }
        public DbSet<Message> Messages { get; set; }
        public DbSet<UserGroup> UserGroups { get; set; }
        public DbSet<Membership> Memberships { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Structure>()
                .Map(m =>
                    {
                        m.MapInheritedProperties();
                        m.ToTable("Structure");
                    });
        }
    }