我是ext.net的新手。我正在尝试使用entitydatasource 制作一个可编辑的网格
这是代码:
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
AutoGenerateOrderByClause="True"
ConnectionString="name=Sample1Entities"
DefaultContainerName="Sample1Entities"
EnableDelete="True"
EnableFlattening="False"
EnableInsert="True"
EnableUpdate="True"
EntitySetName="Customer"
EntityTypeFilter="Customer"
OnUpdating="EntityDataSource1_OnUpdating"
>
<ext:GridPanel
runat="server"
ID="GridPanel1"
Height="570"
Title="Customers"
Frame="true">
<Store>
<ext:Store ID="Store1" runat="server" DataSourceID="EntityDataSource1" AutoSync="true"
IDMode="Client">
<Model>
<ext:Model ID="Model1" runat="server">
<Fields>
<ext:ModelField Name="CustomerId" Mapping="CustomerId" />
<ext:ModelField Name="Name" />
<ext:ModelField Name="Surname" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column ID="Column1" runat="server" DataIndex="CustomerId" Text="CustomerId" Width="150" />
<ext:Column ID="Column2" runat="server" DataIndex="Name" Text="Name" Width="150">
<Editor>
<ext:TextField runat="server" ></ext:TextField>
</Editor>
</ext:Column>
<ext:Column ID="Column3" runat="server" DataIndex="Surname" Text="Surname" Width="150" />
</Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel1" runat="server" Mode="Multi" />
</SelectionModel>
<Plugins>
<ext:CellEditing ID="CellEditing1" runat="server" />
</Plugins>
</ext:GridPanel>
实体类没有问题。我从数据库自动生成并测试了它。当我编辑"名称"列时,会出现以下错误:
System.Exception: The key-value pairs that define an EntityKey cannot be null or empty.rn
Parameter name: record ---> System.ArgumentException: The key-value pairs that define an EntityKey cannot be null or empty.rn
Parameter name: recordrn
at System.Data.EntityKey.CheckValue(String argumentName, String keyFieldName, Object value, PrimitiveType expectedType)rn
at System.Data.EntityKey.CheckKeyValues(EntitySet entitySet, IExtendedDataRecord record, String[]& keyNames, Object& singletonKeyValue, Object[]& compositeKeyValues)rn
at System.Data.EntityKey..ctor(EntitySet entitySet, IExtendedDataRecord record)rn at System.Data.Objects.ObjectStateManager.FixupKey(EntityEntry entry)rn at System.Data.Objects.EntityEntry.AcceptChanges()rn at System.Data.Objects.ObjectContext.AcceptAllChanges()rn at System.Web.UI.WebControls.EntityDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues)rn at System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback)rn at Ext.Net.Store.MakeUpdates(IDataSource ds, JArray data) in C:\Users\Geoffrey McGill\Documents\Visual Studio 2010\Projects\Ext.NET\v2\Ext.Net\Ext\Data\Store.cs:line 890rn at Ext.Net.Store.MakeChanges() in C:\Users\Geoffrey McGill\Documents\Visual Studio 2010\Projects\Ext.NET\v2\Ext.Net\Ext\Data\Store.cs:line 829rn at Ext.Net.Store.DoSaving(String action, String jsonData, JToken parameters) in C:\Users\Geoffrey McGill\Documents\Visual Studio 2010\Projects\Ext.NET\v2\Ext.Net\Ext\Data\Store.cs:line 793rn --- End of inner exception stack trace ---rn at Ext.Net.Store.DoSaving(String action, String jsonData, JToken parameters) in C:\Users\Geoffrey McGill\Documents\Visual Studio 2010\Projects\Ext.NET\v2\Ext.Net\Ext\Data\Store.cs:line 806rn at Ext.Net.Store.RaiseAjaxPostBackEvent(String eventArgument) in C:\Users\Geoffrey McGill\Documents\Visual Studio 2010\Projects\Ext.NET\v2\Ext.Net\Ext\Data\Store.cs:line 1131
当我编辑gridpanel的单元格存储时,发送以下ajax请求;
submitDirectEventConfig:{"config":{"serviceParams":"[{"CustomerId":"3 ","Name":"e","Surname":"soyad1 ","id":null}]"}}
RowSelectionModel1:[{"RecordID":null,"RowIndex":2}]
__EVENTTARGET:ResourceManager1
__EVENTARGUMENT:Store1|postback|updat
e
感谢
最后我修改了ext.net源代码,错误消失了。在store.cs中,a更改了下方的代码
if (id.IsNotEmpty())
{
string idStr = token.Value<string>(id);
int idInt;
if (int.TryParse(idStr, out idInt) && 1==0) // disable this logic
{
keys[id] = idInt;
}
else
{
keys[id] = idStr;
}
}
我希望这个解决方案对你有帮助。
另一步,发现标记的"IdPropery"属性并将其赋值为"CompanyId"值
<ext:Model ID="Model1" runat="server" IDPropery="CompanyId">
然后传递上一个异常。现在它在下面给出了这个例外;
System.Exception: Error while setting property 'id': 'Object of type 'System.Int32' cannot be converted to type 'System.String'.'. ---> System.Web.UI.WebControls.EntityDataSourceValidationException: Error while setting property 'id': 'Object of type 'System.Int32' cannot be converted to type 'System.String'.'.rn
at System.Web.UI.WebControls.EntityDataSourceUtil.SetAllPropertiesWithVerification(EntityDataSourceWrapper entityWrapper, Dictionary`2 changedProperties, Boolean overwrite)rn
at System.Web.UI.WebControls.EntityDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues)rn
at
....
有什么方法可以在Model中使用字符串id字段吗?