目標
C# + ASP.NET MVC 4 で Entity Framework を使用しており、データベース (MySQL) にストアド プロシージャがあります。この手順の結果をビューに表示したいと思います。
問題: 構文がわかりません。
私が持っているもの:データベースコンテキスト(Entity Frameworkによって自動生成)には、次のコードがあります:
public partial class BluMercadosContext : DbContext
{
public BluMercadosContext()
: base("name=BluMercadosContext")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
[...]
public virtual ObjectResult<getProductsListForHome_Result> getProductsListForHome(Nullable<int> inOffer, Nullable<int> categoryId)
{
var inOfferParameter = inOffer.HasValue ?
new ObjectParameter("inOffer", inOffer) :
new ObjectParameter("inOffer", typeof(int));
var categoryIdParameter = categoryId.HasValue ?
new ObjectParameter("categoryId", categoryId) :
new ObjectParameter("categoryId", typeof(int));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<getProductsListForHome_Result>("getProductsListForHome", inOfferParameter, categoryIdParameter);
}
}
ご覧のとおりgetProductsListForHome
、2 つのパラメーターで呼び出されるメソッドがあります。この手順を実行して、ビューに結果を表示したいと考えています。
結果をコントローラー (MVC) を介して渡すか、モデルからビュー (MVVM) に直接渡す必要がありますか?
前もって感謝します。