当数据源为List 时,用于LinqDataSource的ContextTextType和TableName(ContextTextType and TableName for LinqDataSou

编程入门 行业动态 更新时间:2024-10-23 08:37:01
数据源为List 时,用于LinqDataSource的ContextTextType和TableName(ContextTextType and TableName for LinqDataSource when data source is List)

我有一个像这样定义的LinqDataSource:

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

在LinqDataSource_FileSelecting中,它返回/设置List<string>为e.Result,其中e是LinqDataSource的Selecting事件中的EventArgs(LinqDataSourceSelectEventArgs)。 页面加载时出现此错误:

“LinqDataSource'LinqDataSource1'的ContextTypeName属性必须指定数据上下文类型。”

根据这条消息并查看文档,我需要设置LinqDataSource的ContextTypeName和TableName属性。 ContextTypeName通常是类的名称,而TableName将是该类中可枚举属性的名称。

当数据源是一个List<string>我不确定我可以分配什么ContextTypeName或TableName。 我已经尝试了System.Collections.Generic.List<string>作为ContextTypeName,但没有奏效,我收到了“无法加载类型' System.Collections.Generic.List<string> ''”

我意识到,当数据源是在选择事件中生成的List<string>时,LinqDataSource可能不是合适的控件。 但是有没有可以为这种情况设置的ContextTypeName和TableName?

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?

最满意答案

找到答案。 事实证明,当使用Selecting事件并为e.Result分配一个List<string>时,你可以省略ContextTypeName和TableName。 但是,如果将null指定给e.Result,则会发生此错误,因为ASP.NET不知道数据的类型。 我选择事件的代码是为e.Result设置一个非空值,但是一个单独的问题导致null被设置为e.Result ...导致这个错误。

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.

更多推荐

ContextTypeName,LinqDataSource,List<string>,TableName,电脑培训,计算机培训,IT培训"

本文发布于:2023-07-31 01:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340542.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据源   LinqDataSource   List   ContextTextType   data

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!