如何使用具有三层架构的Entity Framework Database First方法调用存储过程将数据绑定到下拉列表?
我在BusinessAccessLayer(项目)中创建了一个业务逻辑类,我使用的是Entity Framework Database First方法。我将对DataAccess图层的引用添加到BusinessAccessLayer。如何从BusinessAccessLayer中的存储过程访问数据。
以下是我的代码:
<asp:DropDownList ID="ddlCategory" runat="server">
<asp:ListItem Selected="True">---->Please select<----</asp:ListItem>
<asp:ListItem>Address</asp:ListItem>
<asp:ListItem>Background</asp:ListItem>
<asp:ListItem>Operations</asp:ListItem>
<asp:ListItem>Groundwater</asp:ListItem>
<asp:ListItem>Soil</asp:ListItem>
<asp:ListItem>Vocs</asp:ListItem>
<asp:ListItem>SurfaceWater</asp:ListItem>
<asp:ListItem>Regulatory/Legal</asp:ListItem>
</asp:DropDownList>
ehsEntities db=new ehsEntities();
//table name is tbl_Category
public IList<tbl_Category> GetCategory()
{
//what is "Database" word below??
var CategoryData =ehsEntities.Database.SqlQuery<T>("SP_GET_WaterReport");
new Object[] { new SqlParameter(categoryID)}).ToList<T>();}
catch (Exception ex)
{
using (CommonManager objCommonController = new CommonManager())
{
objCommonController.LogException("CorporateManager: GetWaterReport - Problem in fetching EW report data", ex, HttpContext.Current.Session["UserName"].ToString());
}
}
return CategoryData;