2012-01-09 6 views
1

に足場コントローラにしようとした後、マップされていなかった私はエラーを取得しています:はタイプがブラウザ

The type 'GMS_Sandbox_MVC.Models.Organization' was not mapped. Check that the type has not been explicitly excluded by using the Ignore method or NotMappedAttribute data annotation. Verify that the type was defined as a class, is not primitive, nested or generic, and does not inherit from EntityObject. Source File: C:\source temp\GMS_Sandbox_MVC\GMS_Sandbox_MVC\Models\OrganizationRepository.cs> > Line: 14

ソースエラー:

Line 12:  { 
Line 13:  // GMSSandboxMVCContext context = new GMSSandboxMVCContext(); 
Line 14:   GMSSandboxMVCContext context = new GMSSandboxMVCContext(); 
Line 15: 
Line 16:   public IQueryable<Organization> All 

誰もがこれを引き起こしている可能性がありますどのような任意のアイデアがありますか?エラーをログに

は言う:

Error 12 The type or namespace name 'GMSSandboxMVCEntities' could not be found (are you missing a using directive or an assembly reference?) C:\source temp\GMS_Sandbox_MVC\GMS_Sandbox_MVC\Models\OrganizationRepository.cs

OrganizationRepository.CS

using System; 
using System.Collections.Generic; 
using System.Data; 
using System.Data.Entity; 
using System.Linq; 
using System.Linq.Expressions; 
using System.Web; 

namespace GMS_Sandbox_MVC.Models 
{ 
public class OrganizationRepository : IOrganizationRepository 
{ 
    // GMSSandboxMVCContext context = new GMSSandboxMVCContext(); 
    GMSSandboxMVCContext context = new GMSSandboxMVCContext(); 

    public IQueryable<Organization> All 
    { 
     get { return context.Organizations; } 
    } 

    public IQueryable<Organization> AllIncluding(params Expression<Func<Organization, object>>[] includeProperties) 
    { 
     IQueryable<Organization> query = context.Organizations; 
     foreach (var includeProperty in includeProperties) { 
      query = query.Include(includeProperty); 
     } 
     return query; 
    } 

    public Organization Find(string id) 
    { 
     return context.Organizations.Find(id); 
    } 

    public void InsertOrUpdate(Organization organization) 
    { 
     if (organization.org_nbr == default(string)) { 
      // New entity 
      context.Organizations.Add(organization); 
     } else { 
      // Existing entity 
      context.Entry(organization).State = EntityState.Modified; 
     } 
    } 

    public void Delete(string id) 
    { 
     var organization = context.Organizations.Find(id); 
     context.Organizations.Remove(organization); 
    } 

    public void Save() 
    { 
     context.SaveChanges(); 
    } 
} 

public interface IOrganizationRepository 
{ 
    IQueryable<Organization> All { get; } 
    IQueryable<Organization> AllIncluding(params Expression<Func<Organization, object>>[] includeProperties); 
    Organization Find(string id); 
    void InsertOrUpdate(Organization organization); 
    void Delete(string id); 
    void Save(); 
} 

} OrganizationController.CS

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 
using GMS_Sandbox_MVC.Models; 

namespace GMS_Sandbox_MVC.Controllers 
{ 
    public class OrganizationController : Controller 
    { 
     private readonly IOrganizationRepository organizationRepository; 

     // If you are using Dependency Injection, you can delete the following constructor 
     public OrganizationController() : this(new OrganizationRepository()) 
     { 
     } 

     public OrganizationController(IOrganizationRepository organizationRepository) 
     { 
      this.organizationRepository = organizationRepository; 
     } 

     // 
     // GET: /Organizations/ 

     public ViewResult Index() 
     { 
      return View(organizationRepository.AllIncluding(organization => organization.Assoc_Role, organization => organization.Grants, organization => organization.Distro_List)); 
     } 

     // 
     // GET: /Organizations/Details/5 

     public ViewResult Details(string id) 
     { 
      return View(organizationRepository.Find(id)); 
     } 

     // 
     // GET: /Organizations/Create 

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

     // 
     // POST: /Organizations/Create 

     [HttpPost] 
     public ActionResult Create(Organization organization) 
     { 
      if (ModelState.IsValid) { 
       organizationRepository.InsertOrUpdate(organization); 
       organizationRepository.Save(); 
       return RedirectToAction("Index"); 
      } else { 
       return View(); 
      } 
     } 

     // 
     // GET: /Organizations/Edit/5 

     public ActionResult Edit(string id) 
     { 
      return View(organizationRepository.Find(id)); 
     } 

     // 
     // POST: /Organizations/Edit/5 

     [HttpPost] 
     public ActionResult Edit(Organization organization) 
     { 
      if (ModelState.IsValid) { 
       organizationRepository.InsertOrUpdate(organization); 
       organizationRepository.Save(); 
       return RedirectToAction("Index"); 
      } else { 
       return View(); 
      } 
     } 

     // 
     // GET: /Organizations/Delete/5 

     public ActionResult Delete(string id) 
     { 
      return View(organizationRepository.Find(id)); 
     } 

     // 
     // POST: /Organizations/Delete/5 

     [HttpPost, ActionName("Delete")] 
     public ActionResult DeleteConfirmed(string id) 
     { 
      organizationRepository.Delete(id); 
      organizationRepository.Save(); 

      return RedirectToAction("Index"); 
     } 
    } 
} 

私はチュートリアルを使用していますhere

+0

私はコードのいくつかの行を見る必要があると思います。 エラーに記載されているすべての条件がOKであることを確認しましたか? – Patricia

答えて

0

私はほとんどこの正確なシナリオに遭遇し、多くの指針を見つけることができませんでした。私のために動作しませんでしたが、価値が行く -

  1. を削除し、あなたのEDMXを再作成:誰にも同様の位置にある場合、私は最終的に試してみる価値かもしれない物事のカップルを発見しました!
  2. 最新バージョンのEFがインストールされていることを確認してください。私はこれに大きな期待を持ちましたが、運がまだありません。
  3. http://jameschambers.com/blog/asp.net-mvcscaffolding-generates-extra-properties-in-views - 私は今、(おそらくcomplex keysに起因する)別のエラーがありますが、私はこれが以前のものを解決したと確信しています!
関連する問題