ObjectDataSource 没有要插入的值

发布于 2024-11-14 16:53:15 字数 1296 浏览 6 评论 0原文

我正在使用 ObjectDataSource 来执行 CRUD 操作。由于某种原因,我收到“ObjectDataSource 'ObjectDataSource1' 没有要插入的值。请检查 'values' 字典是否包含值。”

有什么建议吗?

据我所知,这个控件继承自ObjectDataSource控件。根据文档 http://msdn .microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.insertmethod.aspx

如果设置了 DataObjectTypeName 属性,则以不同的方式解析该方法。 ObjectDataSource 查找具有在 InsertMethod 属性中指定的名称的方法,该方法采用在 DataObjectTypeName 属性中指定的类型的一个参数。

这就是我的 ObjectDataSource 控件的设置方式。

<asp: ObjectDataSource ID="ObjectDataSource1" runat="server" 
                DataObjectTypeName="MyApplication.Entities.Domain.MyObject" ConflictDetection="CompareAllValues"
                OldValuesParameterFormatString="original{0}" SelectMethod="GetUserDisplays"
                InsertMethod="CreateMyObject" UpdateMethod="UpdateMyObject" DeleteMethod="DeleteDisplay">
            </asp:ObjectDataSource>

我在 InsertMethod 上设置了断点,但当我尝试保存表单时应用程序甚至没有命中它。我怀疑由于某种原因 DataObjectType 没有被正确实例化。

我正在尝试在 ASPxGridview 控件的 EditForm 中执行插入操作,DataObjectType 是一个 EF POCO,它具有一些附加属性(标记为虚拟),用于从 ObjectContext 加载相关实体。我认为这可能是问题所在,但不知道如何解决它(到处都看过!!!)。

任何帮助将不胜感激!

I'm using an ObjectDataSource to perform CRUD operations. For some reason I am getting an "ObjectDataSource 'ObjectDataSource1' has no values to insert. Check that the 'values' dictionary contains values."

Any suggestions?

I understand that this control inherits from the ObjectDataSource Control. According to the documentation http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.insertmethod.aspx

If the DataObjectTypeName property is set, the method is resolved in a different way. The ObjectDataSource looks for a method with the name that is specified in the InsertMethod property that takes one parameter of the type that is specified in the DataObjectTypeName property.

That's how my ObjectDataSource Control is setup.

<asp: ObjectDataSource ID="ObjectDataSource1" runat="server" 
                DataObjectTypeName="MyApplication.Entities.Domain.MyObject" ConflictDetection="CompareAllValues"
                OldValuesParameterFormatString="original{0}" SelectMethod="GetUserDisplays"
                InsertMethod="CreateMyObject" UpdateMethod="UpdateMyObject" DeleteMethod="DeleteDisplay">
            </asp:ObjectDataSource>

I set a breakpoint on the InsertMethod, but the application does not even hit it when I try to save my form. I suspect the DataObjectType is not being instantiated properly for some reason.

I'm trying to perform the Insert operation in the EditForm of an ASPxGridview control and the DataObjectType is an EF POCO which has some additional properties (marked virtual) in it to load related entities from the ObjectContext. I think this may be the problem but don't know how to fix it (have looked everywhere!!!).

Any help would be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

栖竹 2024-11-21 16:53:15

尽管我无法准确确定 DataObjectType 没有自动实例化的原因,但我意识到在调用 ObjectDataSource 上的 InsertMethod 之前需要添加一个输入参数。为此,我需要在插入事件中添加输入参数(无论如何在我的场景中)。感谢 StackOverflow 上的另一篇文章,我发现我需要从 ObjectDataSource 中删除“DataObjectTypeName”属性才能触发插入事件。

Although I have not been able to determine exactly why the DataObjectType is not being instantiated automatically, I realized that there was an input parameter that needed to be added prior to calling the InsertMethod on the ObjectDataSource. To do this, I needed to add the input parameter (in my scenario anyway) in the Inserting event. Thanks to another post on StackOverflow I was able to figure out that I needed to remove the 'DataObjectTypeName' attribute from the ObjectDataSource for the Inserting event to fire.

留蓝 2024-11-21 16:53:15

我没有注意到您的 ObjectDataSource 定义中的“TypeName”属性。 DataObjectTypeName 根据 MSDN用于标识“ObjectDataSource 控件在更新、插入或删除数据操作中用作参数的类,而不是从数据绑定控件传递单独的值”。如果类相同(即 CRUD 方法类和数据对象定义类),则两个属性应分配给同一个类。但是,如果您的方法包含在与 DTO 不同的类中,那么您将单独识别每个方法。

I didn't notice a "TypeName" attribute in your ObjectDataSource definition. The DataObjectTypeName according to MSDN is used to identify the class "that the ObjectDataSource control uses for a parameter in an update, insert, or delete data operation, instead of passing individual values from the data-bound control." If the classes are the same (i.e. the CRUD methods class and the data object definition class) then both attributes should be assigned to the same class. If however, your methods are contained in a separate class from your DTO then you would identify each individually.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文