托管实体框架不生成存储过程映射

时间:2022-11-26 02:07:20

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; however, I previously did the following with a different project:

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

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

Now, however, when I type "db." intellisense doesn't see the insert stored procedures. Also, when I search in the InlandMarinaEntities.Designer.cs file, it doesn't have any

但是,现在我键入“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) 

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; 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. What am I missing? Please note that I am using Visual Studio 2010 and SQL Server 2008. TIA.

或者,我理解MEF可以为每个表生成插入,更新和删除操作;但是,当我生成* .edmx文件时,我没有看到添加任何这些操作,并且在通过向导生成* .edmx文件时,我没有看到任何添加它们的选项。我错过了什么?请注意,我使用的是Visual Studio 2010和SQL Server 2008. TIA。

1 个解决方案

#1


0  

Please note that I determined how to add and update database items using the MEF auto-generated functions instead of using stored procedures. Here is how you load an object from the database:

请注意,我确定了如何使用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;
        // ...
    }
}

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代码。

#1


0  

Please note that I determined how to add and update database items using the MEF auto-generated functions instead of using stored procedures. Here is how you load an object from the database:

请注意,我确定了如何使用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;
        // ...
    }
}

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代码。