A
australienadri
Hi,
I am trying to bind a Detailsview to my BSS using an objectdatasource.
The Datasource gets linq entities (customers entries in this case)
from the BSS, one of which is represented in the Detailsview. Apart
from a few string attributes, the LINQ Customer entities also have a
version attribute of type System.Data.Linq.Binary that serves as
timestamp.
When the Datasource tries to update a customer entry by calling my
BSS' UpdateCustomer(Customer ToUpdate) method, the ToUpdate contains
all values of the new customer entry, except that the version
attribute is null, so I can't use linq to update the customer entry
(at least not without ugly workarounds that do not need a version
attribute).
I tried adding a version field to the detailsview, but that only gives
me an exception when calling DetailsView.UpdateItem: "The value of the
parameter "version" cannot be converted from "System.String" to
System.Data.Linq.Binary" (translated from German).
So, the problem is that the objectdatasource does not seem cache the
version attribute of my Linq entity. How can I change this?
Here's the source code of the detailsview and objectdatasource:
<asp:ObjectDataSource ID="CustomerDetailDataSource" runat="server"
DataObjectTypeName="Customer" DeleteMethod="Delete"
SelectMethod="GetCustomerByID" TypeName="CustomerManager"
UpdateMethod="UpdateCustomer">
<SelectParameters>
<asparameter DefaultValue="0" Name="ID" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<aspetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False" DataSourceID="CustomerDetailDataSource"
DefaultMode="Edit">
<Fields>
<asp:BoundField DataField="fname" HeaderText="fname"
SortExpression="fname" />
<asp:BoundField DataField="lname" HeaderText="lname"
SortExpression="lname" />
<asp:BoundField DataField="email" HeaderText="email"
SortExpression="email" />
<asp:BoundField DataField="ID" HeaderText="ID"
SortExpression="ID" ReadOnly="true"/>
<!--
WITHOUT THE NEXT LINE, VERSION IS NULL WHEN UPDATING THE
ENTITY, WITH THE NEXT LINE I GET AN EXCEPTION WHEN UPDATING
-->
<asp:BoundField DataField="version" HeaderText="version"
SortExpression="version" ReadOnly="true"/>
</Fields>
</aspetailsView>
This is what I call to update my database with the new data:
DetailsView1.UpdateItem(true);
Thanks in advance for your help,
Adrian
I am trying to bind a Detailsview to my BSS using an objectdatasource.
The Datasource gets linq entities (customers entries in this case)
from the BSS, one of which is represented in the Detailsview. Apart
from a few string attributes, the LINQ Customer entities also have a
version attribute of type System.Data.Linq.Binary that serves as
timestamp.
When the Datasource tries to update a customer entry by calling my
BSS' UpdateCustomer(Customer ToUpdate) method, the ToUpdate contains
all values of the new customer entry, except that the version
attribute is null, so I can't use linq to update the customer entry
(at least not without ugly workarounds that do not need a version
attribute).
I tried adding a version field to the detailsview, but that only gives
me an exception when calling DetailsView.UpdateItem: "The value of the
parameter "version" cannot be converted from "System.String" to
System.Data.Linq.Binary" (translated from German).
So, the problem is that the objectdatasource does not seem cache the
version attribute of my Linq entity. How can I change this?
Here's the source code of the detailsview and objectdatasource:
<asp:ObjectDataSource ID="CustomerDetailDataSource" runat="server"
DataObjectTypeName="Customer" DeleteMethod="Delete"
SelectMethod="GetCustomerByID" TypeName="CustomerManager"
UpdateMethod="UpdateCustomer">
<SelectParameters>
<asparameter DefaultValue="0" Name="ID" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<aspetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False" DataSourceID="CustomerDetailDataSource"
DefaultMode="Edit">
<Fields>
<asp:BoundField DataField="fname" HeaderText="fname"
SortExpression="fname" />
<asp:BoundField DataField="lname" HeaderText="lname"
SortExpression="lname" />
<asp:BoundField DataField="email" HeaderText="email"
SortExpression="email" />
<asp:BoundField DataField="ID" HeaderText="ID"
SortExpression="ID" ReadOnly="true"/>
<!--
WITHOUT THE NEXT LINE, VERSION IS NULL WHEN UPDATING THE
ENTITY, WITH THE NEXT LINE I GET AN EXCEPTION WHEN UPDATING
-->
<asp:BoundField DataField="version" HeaderText="version"
SortExpression="version" ReadOnly="true"/>
</Fields>
</aspetailsView>
This is what I call to update my database with the new data:
DetailsView1.UpdateItem(true);
Thanks in advance for your help,
Adrian