简体   繁体   English

受管实体框架未生成存储过程映射

[英]Managed Entity Framework not generating stored procedures mappings

Please note that I am attempting to use stored procedures to insert and update table records. 请注意,我正在尝试使用存储过程来插入和更新表记录。 When I add the stored procedure to the database and update the *.edmx file, it sees the stored procedure I've added; 当我将存储过程添加到数据库并更新* .edmx文件时,它会看到我添加的存储过程。 however, I previously did the following with a different project: 但是,我之前在另一个项目中做了以下工作:

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

Now, however, when I type "db." 但是,现在,当我键入“ db”时。 intellisense doesn't see the insert stored procedures. intellisense没有看到插入存储过程。 Also, when I search in the InlandMarinaEntities.Designer.cs file, it doesn't have any 另外,当我在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) 

function. 功能。 Does anyone have any idea as to why it is not adding prBoatUpdate to the *.Designer.cs file? 有谁知道为什么不将prBoatUpdate添加到* .Designer.cs文件?

Alternatively, I understand that MEF can generate Insert, Update and Delete operations for each table; 另外,据我了解,MEF可以为每个表生成插入,更新和删除操作。 however, when I generate the *.edmx file, I don't see any of these operations added, and I don't see any option to add them when going through the wizard to generate the *.edmx file. 但是,当我生成* .edmx文件时,没有看到添加的任何这些操作,并且在通过向导生成* .edmx文件时,看不到添加这些操作的任何选项。 What am I missing? 我想念什么? Please note that I am using Visual Studio 2010 and SQL Server 2008. TIA. 请注意,我正在使用Visual Studio 2010和SQL Server2008。TIA。

Please note that I determined how to add and update database items using the MEF auto-generated functions instead of using stored procedures. 请注意,我确定了如何使用MEF自动生成的功能而不是使用存储过程来添加和更新数据库项。 Here is how you load an object from the database: 这是从数据库加载对象的方式:

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

Here is how to save changes to the boat: 以下是保存更改内容的方法:

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

So MEF not only saves you from writing lots of code for Object Relational Mapping (ORM), it also saves you from writing SQL code for stored procedures or commands. 因此,MEF不仅使您免于编写大量用于对象关系映射(ORM)的代码,而且还使您免于编写存储过程或命令的SQL代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM