Hi
I have a datammodel in linq to SQL that includes a type "Party" which is sub classed twice for "Company" and "Individual". I am trying to bind two repeaters to linq to sql queries as follows
Dim oComp As IEnumerable(Of Company)
Dim oInd As IEnumerable(Of Individual)
oComp = From oP As Company In ERM.Parties _
Where TypeOf (oP) Is Company And _
oP.Name.StartsWith(sSearchString)
oInd = From oP As Individual In ERM.Parties _
Where TypeOf (oP) Is Individual And _
(oP.FirstName.StartsWith(sSearchString) Or _
oP.LastName.StartsWith(sSearchString))
rptIndividuals.DataSource = oInd
rptCompanies.DataSource = oComp
rptCompanies.DataBind()
rptIndividuals.DataBind()
when I step through the code oComp and oInd are IEnumerable of type Company and Individual as expected, but I get the following exception when the first DataBind call is reached
System.MissingMethodException was unhandled by user code Message="Constructor on type 'System.Data.Linq.Provider.DataBindingList
1[[DataModel.Party, DataModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' not found." Source="mscorlib" StackTrace: at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at System.Data.Linq.Provider.BindingList.Create[T](DataContext context, IEnumerable
1 sequence) at System.Data.Linq.DataQuery1.GetNewBindingList() at System.Data.Linq.DataQuery
1.System.ComponentModel.IListSource.GetList() at System.Web.UI.DataSourceHelper.GetResolvedDataSource(Object dataSource, String dataMember) at System.Web.UI.WebControls.ReadOnlyDataSource.System.Web.UI.IDataSource.GetView(String viewName) at System.Web.UI.WebControls.Repeater.ConnectToDataSourceView() at System.Web.UI.WebControls.Repeater.GetData() at System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) at System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) at System.Web.UI.WebControls.Repeater.DataBind() at parties.lbHiddenPostback_Click(Object sender, EventArgs e) in \parties.aspx.vb:line 491 at System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) InnerException:
if I then select everything as parties instead as follows, it all works ok
Dim oComp As IEnumerable(Of Party)
Dim oInd As IEnumerable(Of Party)
oComp = From oP In ERM.Parties _
Where TypeOf (oP) Is Company And _
CType(oP, Company).Name.StartsWith(sSearchString)
oInd = From oP In ERM.Parties _
Where TypeOf (oP) Is Individual And _
(CType(oP, Individual).FirstName.StartsWith(sSearchString) Or _
CType(oP, Individual).LastName.StartsWith(sSearchString))
rptIndividuals.DataSource = oInd
rptCompanies.DataSource = oComp
rptCompanies.DataBind()
rptIndividuals.DataBind()
there is nothing in either repeater that relates to the data returned yet, just a label in the item template to show me how many records are returned for each query.
It doesn't make sense to me that I have to bind to the parent type, I will be unable to access the attributes associated with Individual and Company without first casting to this type! any help or pointers much appreciated.