我需要返回什么集合才能支持WCF中的筛选
本文关键字:WCF 支持 筛选 返回 什么 集合 | 更新日期: 2023-09-27 18:00:41
我有一个WCF客户端,我需要将DTO放入BindingSource中,但当我尝试将筛选器应用于BindingSource时,它既不能作为列表,也不能作为BindingList,因为两者都为IBindingListView.SupportsFiltering
返回false。
我需要使用什么数据类型才能在列表中进行筛选?
代理DTO:
namespace MyApp.DataContracts
{
[System.Runtime.Serialization.DataContractAttribute(Name = "ServerSetupDTO", Namespace = "http://example.com/MyApp")]
[System.SerializableAttribute()]
public partial class ServerSetupDTO : object, System.Runtime.Serialization.IExtensibleDataObject
{
[System.Runtime.Serialization.DataMemberAttribute()]
public System.ComponentModel.BindingList<MyApp.DataContracts.DatabaseInfo> GenericPreconfigs
{
//(Snip)
}
//(Snip)
}
[System.Runtime.Serialization.DataContractAttribute(Name = "DatabaseInfo", Namespace = "http://example.com/MyApp")]
[System.SerializableAttribute()]
public partial class DatabaseInfo : object, System.Runtime.Serialization.IExtensibleDataObject
{
[System.Runtime.Serialization.DataMemberAttribute()]
public string AllowedServer
{
//(Snip)
}
//(Snip)
}
}
应用过滤器:
ServerSetupDTO serverSetupDTO = proxyClient.GetServerSetup();
bsServerSettings.DataSource = serverSetupDTO ;
bsPreconfigList.DataMember = "GenericPreconfigs";
bsPreconfigList.DataSource = bsServerSettings;
//This filter never gets applied, bsPreconfigList.SupportsFiltering is false.
bsPreconfigList.Filter = String.Format("AllowedServer = '{0}'", cmbHost.Text);
在彻底崩溃后,我决定只制作一个ToDataSet函数,因为我永远不需要更新值。
public partial class ServerSetupDTO
{
public DataSet ToDataSet()
{
var setupDataSet = new DataSet("ServerSetup");
//Get the demos
var demoPreconfigsTable = setupDataSet.Tables.Add("DemoPreconfigs");
demoPreconfigsTable.Columns.Add("AllowedServer");
demoPreconfigsTable.Columns.Add("SqlInstance");
demoPreconfigsTable.Columns.Add("DatabaseName");
this.DemoPreconfigs.ForEach(item => demoPreconfigsTable.Rows.Add(item.AllowedServer, item.SqlInstance, item.DatabaseName));
//Get the preconfigs
var genericPreconfigsTable = setupDataSet.Tables.Add("GenericPreconfigs");
genericPreconfigsTable.Columns.Add("AllowedServer");
genericPreconfigsTable.Columns.Add("SqlInstance");
genericPreconfigsTable.Columns.Add("DatabaseName");
this.GenericPreconfigs.ForEach(item => genericPreconfigsTable.Rows.Add(item.AllowedServer, item.SqlInstance, item.DatabaseName));
//Get the servers
var sqlServersTable = setupDataSet.Tables.Add("SqlServers");
sqlServersTable.Columns.Add("ServerName");
this.SqlServers.ForEach(item => sqlServersTable.Rows.Add(item));
//Get the VM's
var virtualMachinesTable = setupDataSet.Tables.Add("VirtualMachines");
virtualMachinesTable.Columns.Add("MachineName");
this.VirtualMachines.ForEach(item => virtualMachinesTable.Rows.Add(item));
return setupDataSet;
}
}
然后我只更新我的一行代码到这个
bsServerSettings.DataSource = Program.ServerSettings.ToDataSet();