gpt4 book ai didi

c# - 在 MVC 中调用存储过程

转载 作者:行者123 更新时间:2023-11-30 23:30:35 25 4
gpt4 key购买 nike

<分区>

Menulistfunctionimport我有一个存储过程,我正在尝试调用它以将结果返回到我的 View 中。我的模型文件夹中有一个类,我正试图从中调用它。

 public  class MasterMenu
{

public List<USP_MenuList_ForUser_G_Result> GetMenus(int userId)
{


List<USP_MenuList_ForUser_G_Result> GetMenuListForUser = null;
using (MenuEntities dataContext = new MenuEntities())
{
GetMenuListForUser = dataContext.USP_MenuList_ForUser_G(56367).ToList();
return GetMenuListForUser;
}
}

我正试图像这样达到我的观点

<body>

<div id="header">
<div id="logo">
</div>

</div>
@if (Model.GetMenus(56367) != null && Model.GetMenus(56367).Count > 0)
{ }



@RenderBody()
</body>

我不确定在我的 Controller 中做什么才能到达存储过程。该过程采用一个参数,即用户 ID,它需要访问的所有表都在我的 EDMX 中。这是我的 Controller 的样子。

public class MasterMenuController : Controller
{
private MenuEntities menuEntities = new MenuEntities();
}

我也有这个类,它看起来像一个数据库上下文类,但它是在我创建 EDMX 时自动生成的。

//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Adds.Areas.Mvc.Menu.Models
{
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Core.Objects;
using System.Linq;

public partial class MenuEntities : DbContext
{
public MenuEntities()
: base("name=MenuEntities")
{
}

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}

public virtual DbSet<tblAgent> tblAgents { get; set; }
public virtual DbSet<tblMenu> tblMenus { get; set; }
public virtual DbSet<tblQualifier> tblQualifiers { get; set; }
public virtual DbSet<tblRoleMenuMapping> tblRoleMenuMappings { get; set; }
public virtual DbSet<tblRole> tblRoles { get; set; }
public virtual DbSet<tblUserRoleMapping> tblUserRoleMappings { get; set; }
public virtual DbSet<tblUsersLogin> tblUsersLogins { get; set; }
public virtual DbSet<tblUserMenuMapping> tblUserMenuMappings { get; set; }

public virtual ObjectResult<USP_MenuList_ForUser_G_Result> USP_MenuList_ForUser_G(Nullable<int> userID)
{
var userIDParameter = userID.HasValue ?
new ObjectParameter("UserID", userID) :
new ObjectParameter("UserID", typeof(int));

return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<USP_MenuList_ForUser_G_Result>("USP_MenuList_ForUser_G", userIDParameter);
}
}
}

MenuModelExplorer

MenuEntities

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com