2011-12-10 85 views
0

我一直有數據訪問間歇性的麻煩,所以我正在重建我的項目。我有一個3層架構,通過DATA(DL)層將我的數據庫與我的App_Data文件夾一起使用Linq to Entities。數據的唯一連接字符串位於數據層(DL)web.config中。ASP.Net Linq to Entities:使用3層架構時的Web配置連接字符串

我在我的UI在「變種GetFeatured」聲明指出,「類型‘DL.RESTAURANT’在未引用的程序集定義得到一個錯誤信息。你必須添加到程序集的引用「DL「。我在用戶界面中提供了業務邏輯層的參考信息,業務邏輯層提供了對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; 
    } 
    } 
} 
+0

您意識到您直接從UI查詢您的DAL,而不是實際使用業務層類。 – tvanfosson

+0

對不起,我不這麼認爲。 BLgetFeatured obj2 = new BLgetFeatured(); int one = 29; int two = 54; int three = 49; int four = 41; int restID = 1; var GetFeatured = obj2.getFeatured(restID); – Susan

+0

看看上面的代碼(我已經將更多的代碼添加到了UI中),並且我相信BLgetFeatured obj2 = new BLgetFeatured(),它將進入我的BL層。這是不正確的? – Susan

回答

0

在UI項目中添加對DL的引用。由於您在UI項目中使用該類型,因此需要對其進行參考。

+0

當我試圖讓我的數據訪問與UI分開時,是否會導致3層架構出現問題?我有點以爲我明白,從我的ASP.Net類... ??? – Susan