ContextTextType and TableName for LinqDataSource when data source is List

asp.netlinqdatasource

I have a LinqDataSource defined like this:

<asp:LinqDataSource ID="LinqDataSource1" runat="server" OnSelecting="LinqDataSource_FileSelecting"></asp:LinqDataSource>

In LinqDataSource_FileSelecting, it returns/sets a List<string> to e.Result, where e is the EventArgs (LinqDataSourceSelectEventArgs) in the Selecting event of the LinqDataSource. I'm getting this error when the page loads:

"The ContextTypeName property of LinqDataSource 'LinqDataSource1' must specify a data context type."

Based on this message and looking at the docs, I need to set the ContextTypeName and TableName properties of the LinqDataSource. ContextTypeName would normally be the name of a class, and TableName would be the name of an enumerable property within that class.

When the data source is a List<string> I'm not sure what ContextTypeName or TableName I can assign. I've tried System.Collections.Generic.List<string> for the ContextTypeName, but that didn't work, I received "Could not load type 'System.Collections.Generic.List<string>'"

I realize the LinqDataSource may not be the appropriate control when the data source is a List<string> generated within the Selecting event. But is there a ContextTypeName and TableName I can set for this scenario?

Best Answer

Found the answer. Turns out that you can omit ContextTypeName and TableName when using the Selecting event and assigning a List<string> to e.Result. However, if you assign null to e.Result, then this error will occur since ASP.NET doesn't know the type of data. My code on the Selecting event was designed to set a non-null value to e.Result, but a separate problem was leading to null being set to e.Result ... leading to this error.

Related Topic