簡體   English   中英

受管實體框架未生成存儲過程映射

[英]Managed Entity Framework not generating stored procedures mappings

請注意,我正在嘗試使用存儲過程來插入和更新表記錄。 當我將存儲過程添加到數據庫並更新* .edmx文件時,它會看到我添加的存儲過程。 但是,我之前在另一個項目中做了以下工作:

var db = new MyMarinaEntities();
db.prBoatInsert(registrationNumber, manufacturer, modelYear, length, customerID);

但是,現在,當我鍵入“ db”時。 intellisense沒有看到插入存儲過程。 另外,當我在InlandMarinaEntities.Designer.cs文件中搜索時,它沒有任何內容

public int prBoatUpdate(Nullable<global::System.Int32> boatID, global::System.String registrationNumber, global::System.String manufacturer, Nullable<global::System.Int32> modelYear, Nullable<global::System.Int32> length, Nullable<global::System.Int32> customerID) 

功能。 有誰知道為什么不將prBoatUpdate添加到* .Designer.cs文件?

另外,據我了解,MEF可以為每個表生成插入,更新和刪除操作。 但是,當我生成* .edmx文件時,沒有看到添加的任何這些操作,並且在通過向導生成* .edmx文件時,看不到添加這些操作的任何選項。 我想念什么? 請注意,我正在使用Visual Studio 2010和SQL Server2008。TIA。

請注意,我確定了如何使用MEF自動生成的功能而不是使用存儲過程來添加和更新數據庫項。 這是從數據庫加載對象的方式:

private void LoadBoat(int boatID)
{
    using (var db = new MyMarinaEntities())
    {
        var boat = db.Boats.SingleOrDefault(b => (b.BoatID == boatID));

        this.chkIsRental.Checked = boat.IsRental;
        this.chkInactive.Checked = boat.Inactive;
        this.txtLength.Text = boat.Length;
        this.txtManufacturer = boat.Manufacturer;
        // ...
    }
}

以下是保存更改內容的方法:

protected void btnSave_click(object sender, EventArgs args)
{
    using (var dm = new MyMarinaEntities())
    {
        MyMarinaEntities boat;

        boat.IsRental = this.chkIsRental.Checked;
        boat.Inactive = this.chkInactive.Checked;
        boat.Length = this.txtLength.Text;
        boat.Manufacturer = this.txtManufacturer;
        // ...
        if (boatID.Value == "") 
            dm.AddObject("Boats", boat);
        dm.SaveChanges();
    }
}

因此,MEF不僅使您免於編寫大量用於對象關系映射(ORM)的代碼,而且還使您免於編寫存儲過程或命令的SQL代碼。

暫無
暫無

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

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