c# - How to create BindingList which is subset of DbSet while using Table Per Hierachy inheritance approach? -
i have dbset<person> contains objects of type: person, client,employee indicated discriminator in table. used table per hierarchy approach.
now try bindinglist of client set datasource of listbox.
i able set whole people table datasource want clients form table in listbox.
public partial class listofclientsform : form { private applicationdbcontext context; public bindinglist<person> clients { get; set; } public bindingsource psource { get; set; } public listofclientsform() { initializecomponent(); context = new applicationdbcontext(); populatelistbox(); } public void populatelistbox() { context.people.load(); clients = context.people.local.tobindinglist(); clients.allowedit = true; clients.allownew = true; psource = new bindingsource(); psource.datasource = clients; clientslistbox.datasource = psource; //now whole contents of array in listbox } } to conclude wish have public bindinglist<clients> clients { get; set; } instead of public bindinglist<person> clients { get; set; }.
if want bring clients elements context, can filter people before load them:
context.people.oftype<client>().load(); //you going clients clients = context.people.local.tobindinglist();
Comments
Post a Comment