我正在使用最新版本的实体框架查询有关导航属性的奇怪问题。导航属性无法正常工作
我有其中我有被标记为虚拟几个所需导航性能的实体。 见下面我的实体类:
public class Folder : UserReferencedEntityBase<int>
{
#region Constructors
public Folder()
{ }
public Folder(IUnitOfWork unitOfWork)
: base(unitOfWork)
{
ParentFolder = unitOfWork.Context.GetCurrentFolder as Folder;
}
#endregion
#region Properties
[Required]
public string Name { get; set; }
[Required]
public string Data { get; set; }
[Column(Order = 998)]
public Folder ParentFolder { get; set; }
[Required]
public bool IsPublished { get; set; }
#endregion
}
这一个是从UserReferencedEntityBase{T}
它看起来像继承:
public class UserReferencedEntityBase<TKey> : EntityBase<TKey>
{
#region Constructors
public UserReferencedEntityBase() { }
public UserReferencedEntityBase(IUnitOfWork unitOfWork)
{
unitOfWork.ThrowIfNull("unitOfWork");
CreatedBy = unitOfWork.Context.GetCurrentUser;
}
#endregion
#region Properties
[Required]
[Column(Order = 996)]
public virtual IdentityUser CreatedBy { get; set; }
[Column(Order = 997)]
public virtual IdentityUser UpdatedBy { get; set; }
#endregion
}
现在,我有我的MVC网站,我加载一个实体,更新属性并将其保存在数据库中:
var model = new FolderManager(UnitOfWork).GetFolder(id);
model.IsPublished = true;
UnitOfWork.Commit();
我在这里使用自定义工作单元,但没有任何火箭科学。一切都与同样的背景下发生的,在同一个请求中,没有异步调用,...
当我执行的代码,我收到:
Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
见到这种情景,揭示了以下错误:
"The CreatedBy field is required."
现在,奇怪的是这样的,当我调试我的代码,上面给出的3线,在CREATED_BY财产填充和代码中并没有任何问题执行。
我使用ASP.NET身份框架,从而利用该事项情况下IdentityDbContext。
任何人都有线索?
亲切的问候
更新 - 文件夹管理器
经理是只是一个包装,让我的内容,我的工作单位:
public Folder GetFolder(int id)
{
return UnitOfWork.FolderRepository.GetByFilter(x => x.Id == id);
}
的GetByFilter方法构造像:
public virtual TEntity GetByFilter(Func<TEntity, bool> filter)
{
DbSet.ThrowIfNull("DbSet");
if (OnBeforeEntityGet != null)
{ OnBeforeEntityGet(this, new RepositoryEventArgs(typeof(TEntity))); }
if (OnEntityGet != null)
{ OnEntityGet(this, new RepositoryEventArgs(typeof(TEntity))); }
return !Entities.Any() ? null : !Entities.Where(filter).Any() ? null : Entities.First(filter);
}
什么是'FolderManager',它是如何让你的'文件夹'实例? – 2014-11-14 14:43:24
[避免插入标题到标题](http://stackoverflow.com/help/tagging) – BCdotWEB 2014-11-14 14:50:57
请参阅我更新的问题。 – Complexity 2014-11-14 14:56:38