2009-07-28 14 views
1

私はカスタムエンティティを作成しました。これは、エンティティにL2Sの結合からのデータを移入する必要があるためです。カスタムLinq2Sqlクラスに基づいて厳密に型指定されたMVCビューを作成する方法

コントローラのActionResultコードを右クリックして「ビューを追加」し、「強く型付けされたビューを作成」を選択すると、セレクタで使用できるクラスにクラスが表示されません。なぜ私は分からない。私のコードは次のとおりです。

//The Model 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Data; 
using System.Data.SqlClient; 

namespace FurnitureStore.Models.Repository 
{ 
    public class FurnitureRepository 
    { 
     public IQueryable<Listing> GetProductListings() 
     { 
      FurnitureDataContext dc = new FurnitureDataContext(); 

     return (from p in dc.Products 
       join c in dc.Categories 
       on p.CategoryId equals c.CategoryId 
       select new Listing 
       { 
        ProductName = p.ProductName, 
        CategoryDescription = c.CategoryDescription 
       }); 
    } 
} 
} 

//The entity class 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 

namespace FurnitureStore.Models 
{ 
    public class Listing 
    { 
     public string ProductName { get; set; } 
     public string CategoryDescription { get; set; } 
    } 
} 

//The Method in the Controller 
public ActionResult ProductListings() 
{ 
    FurnitureRepository fr = new FurnitureRepository(); 
    var listings = fr.GetProductListings(); 
    return View("ProductListings",listings); 
} 

答えて

1

通常のビューを作成し、ビューのページ定義(特に属性を継承します)を編集するだけです。

<%@ Page ... Inherits="System.Web.Mvc.ViewPage<IQueryable<FurnitureStore.Models.Listing>>" %> 

あなたのクラスセレクタに表示されない理由は私の頭の上にはありません。

HTHS
チャールズ

3

は、コードがコンパイルされていない場合は、新しく追加されたクラスは、セレクタで使用可能なクラスに見せつけるいけない、コードをコンパイルしていることを確認し解決するために絶対的に正しい方法です

+1

この! –

関連する問題