奇怪的行为将多个列恢复为EntityDataSource中的单个字段

时间:2015-01-29 14:03:54

标签: asp.net linq webforms entity-framework-6 entitydatasource

我在aspx页面中使用此EntityDataSource从我的数据库中检索一些数据:

<asp:EntityDataSource ID="mydatasource" runat="server" 
    ConnectionString="name=myconnectionstring" 
    DefaultContainerName="mydefaultcontainer"
    EnableFlattening="False"
    EntitySetName="Tasks" 
    Select="it.[ID], (it.ID + ' - ' + ISNULL(it.Name, ' ')) as [FullTaskName]" //Second argument of ISNULL is a whitespace.
    Where="it.Project = @projectID" > 

    <WhereParameters>
        <asp:ControlParameter ControlID="tbProject" Name="projectID" PropertyName="Text" Type="String" />
    </WhereParameters>
</asp:EntityDataSource>

如您所见,我选择2个字段(ID +名称)的组合作为单个字段,因此我可以在下拉列表中使用它。

在Task表中,字段Name可以为null,在这种情况下,整个FullTask​​Name变为null(或空字符串,我不确定)。

ID  Name
0   Name0
1   NULL
2   Name2

有了这些数据,我的预期输出将是这样的:

0 - Name0
1 - 
2 - Name2

但我得到了这个:

0 - Name0

2 - Name2
  • 这是预期的行为吗?
  • 我如何获得预期的输出? (我尝试使用&#34; ISNULL(column_name,replace_with_this_string)&#34;函数,但我得到一个&#34; isnull无法解析为有效类型或函数&#34;错误。

0 个答案:

没有答案