EF 4.1 RC1 - 一个或多个实体的验证失败 - 但数据有效并在CTP5中工作 [英] EF 4.1 RC1 - Validation failed for one or more entities - But the data is valid and worked in CTP5

查看:75
本文介绍了EF 4.1 RC1 - 一个或多个实体的验证失败 - 但数据有效并在CTP5中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这让我很难过。

我首先使用EF 4.1 RC代码创建MVC 3应用程序,工作单元模式,存储库模式和视图模型/模型映射automapper。

I have an MVC 3 application using EF 4.1 RC code first, the Unit of Work pattern, the Repository pattern and viewmodel/model mapping with automapper.

我一直在使用EF 4.1 CTP5而没有任何问题。

I have been using EF 4.1 CTP5 without any problems what so ever.

 

我有一个看起来像这样的控制器

I have a controller that looks something like this

 


 [HttpPost]
 public ActionResult Index(AccountProfileIndexViewModel accountInformation)
 {
 if (ModelState.IsValid)
 {
 var accountProfile = _accountProfileRepository.GetById(accountInformation.AccountProfileId);

 var mappedAccountInformation = _mappingEngine.Map(accountInformation, accountProfile);

 _unitOfWork.Commit();

 ViewBag.UpdateSuccessful = true;

 return View(accountInformation);
 }

 return View(accountInformation);
 }

推荐答案

我发现它与数据不存在有关加载到对象中。

I've discovered that it has to do with the data not being loaded in the object.

如果我在提交方法之前添加一些跟踪代码,它可以正常工作。

If I add some trace code before the commit method, it works fine.


          Trace.TraceInformation("Number of Linked User Profiles: {0}", result.LinkedUserProfiles.Count.ToString());
          Trace.TraceInformation("Primary Contact first name: {0}", result.PrimaryContact.FirstName);


这篇关于EF 4.1 RC1 - 一个或多个实体的验证失败 - 但数据有效并在CTP5中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆