2011-06-14 17 views
2

これは私のコントローラクラスです。'WareHouse'の 'ModifiedOn'プロパティを 'DateTime'値に設定できませんでした。このプロパティを 'String'型のnull以外の値に設定する必要があります

namespace CalcoWOMS.Controllers 
{ 
    public class AdminController : Controller 
    { 
     private WOMSEntities db = new WOMSEntities(); 

     public ViewResult WareHouseIndex() 
     { 
      return View(db.WareHouse.ToList()); 
     } 



     public ViewResult WareHouseDetails(int id) 
     { 
      WareHouse wareHouse = db.WareHouse.Single(m => m.ID == id); 
      return View(wareHouse); 
     } 

     public ActionResult WareHouseCreate() 
     { 
      return View(); 
     } 


     [HttpPost] 
     public ActionResult Create(WareHouse wareHouse) 
     { 
      if (ModelState.IsValid) 
      { 
       db.WareHouse.AddObject(wareHouse); 
       db.SaveChanges(); 
       return RedirectToAction("WareHouseIndex"); 
      } 

      return View(wareHouse); 
     } 

     // 
     // GET: /Admin/Edit/5 

     public ActionResult WareHouseEdit(int id) 
     { 
      WareHouse wareHouse = db.WareHouse.Single(m => m.ID == id); 
      return View(wareHouse); 
     } 



     [HttpPost] 
     public ActionResult WareHouseEdit(WareHouse wareHouse) 
     { 
      if (ModelState.IsValid) 
      { 
       db.WareHouse.Attach(wareHouse); 
       db.ObjectStateManager.ChangeObjectState(wareHouse, EntityState.Modified); 
       db.SaveChanges(); 
       return RedirectToAction("WareHouseIndex"); 
      } 
      return View(wareHouse); 
     } 

     // 
     // GET: /Admin/Delete/5 

     public ActionResult WareHouseDelete(int id) 
     { 
      WareHouse wareHouse = db.WareHouse.Single(m => m.ID == id); 
      return View(wareHouse); 
     } 


     [HttpPost, ActionName("WareHouseDelete")] 
     public ActionResult WareHouseDeleteConfirmed(int id) 
     { 
      WareHouse wareHouse = db.WareHouse.Single(m => m.ID == id); 
      db.WareHouse.DeleteObject(wareHouse); 
      db.SaveChanges(); 
      return RedirectToAction("WareHouseIndex"); 
     } 
    } 
} 

、これが私のテーブルの設計..です

this is image of my table design

i "が管理/ WareHouseIndex" アクションを実行したい時はいつでも発生した問題がある「オン 'ModifiedOn' プロパティ」 ですWareHouse 'を' DateTime '値に設定できませんでした。このプロパティを' String '型のnull以外の値に設定する必要があります。

私はmodifiedOnフィールドにnullエントリがありません。それを確認して、私が何をしたのか教えてください。

+0

これは例外のどのタイプですか? WareHouse.ModifiedOnプロパティの種類と属性はどのようになっていますか?どのようにデータベースにマップされますか? –

+0

WareHouseクラスのコード、特にコンストラクタを表示できますか?そして、あなたはEntity Frameworkを使用していると思いますか? – 37Stars

答えて

0

Database Typeとその施設のPOCO Typeの間にタイプの不一致がある可能性があります。私は推測していた場合、すなわち、私はあなたの財産の種類がStringまたはnull非許容のDateTimeだと思いますし、それがNULL可能DateTime次のようになります。

public DateTime? ModifiedOn { get; set; } 
関連する問題