Search code examples
asp.netlinq-to-entitiesweb-config3-tier

ASP.Net Linq to Entities: Web Config connection string when used 3-tier architecture


I have been having intermittent trouble with data access so I'm rebuilding my project. I have a 3-tiere architecture using Linq to Entities with my App_Data folder with my database in by DATA (DL) layer. The only connection string to the data is in the Data layer (DL) web.config.

I am getting a error message in my UI in the 'var GetFeatured' statement that states that "The type 'DL.RESTAURANT' is defined in an assembly that is not referenced. You must add a reference to assembly 'DL." I have a reference in the UI to the Business Logic layer and the Business Logic layer has a reference to DL. What am I missing?

USER INTERFACE CODE-BEHIND

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;

BUSINESS LOGIC LAYER

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;
    }
  }
}

Data Layer (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;
    }
  }
}

Solution

  • Add a reference to DL in your UI project. Since you are using that type in the UI project, you need a reference to it.