【发布时间】:2011-12-10 19:28:02
【问题描述】:
我在数据访问方面遇到了间歇性问题,因此我正在重建我的项目。我有一个 3 层架构,使用 Linq to Entities 和我的 App_Data 文件夹以及我的数据库在 DATA (DL) 层。数据的唯一连接字符串位于数据层 (DL) web.config 中。
我在 UI 中的 'var GetFeatured' 语句中收到一条错误消息,指出“'DL.RESTAURANT' 类型是在未引用的程序集中定义的。您必须添加对程序集“DL”的引用。我在 UI 中引用了业务逻辑层,而业务逻辑层引用了 DL。我错过了什么?
用户界面代码隐藏
BLgetFeatured obj2 = new BLgetFeatured();
int one = 29;
int two = 54;
int three = 49;
int four = 41;
int restID = one;
var GetFeatured = obj2.getFeatured(restID);
var GetFeatured = obj2.getFeatured(restID);
litRestName.Text = GetFeatured[0].REST_NAME;
litRestStreet.Text = GetFeatured[0].REST_STREET1;
litRestPhone.Text = GetFeatured[0].REST_PHONE;
litRestCity.Text = GetFeatured[0].CITY.CITY_NAME;
litRestCuisine.Text = GetFeatured[0].CUISINE.CUISINE_NAME;
litRestShortDesc.Text = GetFeatured[0].REST_DESC;
restImage.ImageUrl = "~/Images/" + GetFeatured[0].REST_IMAGE;
业务逻辑层
using DL;
namespace BL
{
public class BLgetRestaurants
{
public List<RESTAURANT> getRestaurants(string cuisineName, string cityName, string priceName, string ratingName)
{
DLgetRestaurants obj = new DLgetRestaurants();
var restaurantList = obj.getRestaurants(cuisineName, cityName, priceName, ratingName);
return restaurantList;
}
}
}
数据层 (DL)
namespace DL
{
public class DLgetFeatured
{
FCGuide db = new FCGuide();
public List<RESTAURANT> getFeatured(int restID)
{
var restList = (from RESTAURANT in db.RESTAURANTs.Include("CUISINE").Include("CITY")
where RESTAURANT.REST_ID == restID
select RESTAURANT).ToList();
var result = (from RESTAURANT in db.RESTAURANTs.Include("CITY").Include("CUISINE")
where RESTAURANT.CUISINE.CUISINE_ID == RESTAURANT.CUISINE_ID
&& RESTAURANT.CITY.CITY_ID == RESTAURANT.CITY_ID
orderby RESTAURANT.REST_NAME ascending
select RESTAURANT).ToList();
return restList;
}
}
}
【问题讨论】:
-
您意识到您是直接从 UI 查询 DAL 而不是实际使用业务层类。
-
对不起,我不这么认为。 BLgetFeatured obj2 = new BLgetFeatured();整数一 = 29;整数二 = 54;整数三 = 49;整数四 = 41; int restID = 一; var GetFeatured = obj2.getFeatured(restID);
-
看看上面的代码(我已经在 UI 中添加了更多代码),我相信 BLgetFeatured obj2 = new BLgetFeatured() 将进入我的 BL 层。这不正确吗?
-
tvanfosson- 你有时间看看我的 cmets 吗?非常感谢您的帮助。
-
您一定没有包含相关代码。我没有看到 getFeatured 方法或 BLgetFeatured 类。无论如何,您使用的是 DL 中存在的 RESTAURANT 对象,并且需要您将 DL 作为引用包含在内,以便它了解类型。
标签: asp.net linq-to-entities web-config 3-tier