0

请注意,我正在尝试使用存储过程来插入和更新表记录。当我将存储过程添加到数据库并更新 *.edmx 文件时,它会看到我添加的存储过程;但是,我之前对不同的项目做了以下操作:

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

但是,现在,当我键入“db”时。智能感知看不到插入存储过程。另外,当我在 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 Server 2008。TIA。

4

1 回答 1

0

请注意,我确定了如何使用 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 代码。

于 2013-12-03T04:43:06.593 回答