簡體   English   中英

編譯錯誤:類型是在未引用的程序集中定義的

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

我正在研究3層應用程序。 我使用O / R設計器在SQL表(LEAVE)中添加了Linq。 我添加了以下方法,用於從業務層中的類(LeaveRecord)中的表(LEAVE)中檢索數據。

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

在UI層上,在Webform背后的代碼中,我嘗試獲取如下數據:

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

運行該程序時,出現編譯錯誤:

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).

我該如何解決這個問題?

您正在從bll中公開dal數據類型。 因此,如果有人想使用bll API(即您的UI),則還需要引用dal

所以,你有你的引用的選擇dalUI還是在做一個數據類型開關bll和揭露是在定義新的數據類型bll

最簡單的解決方案是從UI項目中添加對dal的引用。

您必須封送數據對象:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM