Chibuzo
Chibuzo

Reputation: 6117

Compile ERROR: The type is defined in an assembly that is not referenced

I'm working on a 3-tier application. I added a Linq to SQL table (LEAVE) using the O/R Designer. I added the method below for retrieving data from the table (LEAVE) in a class (LeaveRecord) in the Business Layer.

public IQueryable<LEAVE> getLeaves()
{
    dbContext db = new dbContext;
    return db.LEAVEs;
}

On the UI layer, in the code behind for the webform, I tried to get the data like this:

bll.LeaveRecord leaveRecords = new bll.LeaveRecord();
var data = leaveRecords.getLeaves(); // the error message highlights this line (41) as the offender

When I run the program, I get a compilation error:

The type 'programname.dal.LEAVE' is defined in an assembly that is not referenced. You must add a reference to assembly 'programname.dal, version=1.0.0.0, Culture=neutral, PublicKeyToken=null' (Line 41).

How can I resolve this issue?

Upvotes: 0

Views: 3029

Answers (3)

John Koerner
John Koerner

Reputation: 38077

You are exposing dal data types from your bll. Thus if anyone wants to consume that the bll API (i.e. your UI) would need to also reference the dal.

So you have the choice of referencing your dal from your UI or doing a data type switch in the bll and exposing new data type that is defined in the bll.

Upvotes: 2

John Castleman
John Castleman

Reputation: 1561

You have to marshal your data objects:

public DaoLeave
{
    // Properties of DaoLeave, same as properties of LEAVE

    internal void DaoLeave(LEAVE doLeave)
    {
        // set properties from properties ... alternately, use something like AutoMapper
    }
}

public IQueryable<DaoLeave> getLeaves()
{
    dbContext db = new dbContext;
    return db.LEAVEs.Select(l => new DaoLeave(l));
}

Upvotes: 0

Iswanto San
Iswanto San

Reputation: 18569

The most simple solution is add reference to dal from the UI project.

Upvotes: 2

Related Questions