0

I'm using this EntityDataSource in a aspx page to retrieve some data from my database:

<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>

As you can see, im selecting the combination of 2 fields (ID + Name) as a single field, so i can use it in a dropdownlist.

In the Task table, the field Name can be null, and in that case the whole FullTaskName become null (or empty string, im not sure).

ID  Name
0   Name0
1   NULL
2   Name2

With this data, my expected output will be like this:

0 - Name0
1 - 
2 - Name2

But instead i got this:

0 - Name0

2 - Name2
  • Is this the intended behaviour?
  • How can i get my expected output? (I tried to use the "ISNULL(column_name, replace_with_this_string)" function, but i get an "isnull cannot be resolved into valid type or function" error.
Kitinz
  • 1,522
  • 3
  • 17
  • 28
  • How did `ISNULL` not work? There's no LINQ in your question, can you update it to see what are you doing with the `EntityDataSource` that didn't work when using `ISNULL`? – Honza Brestan Jan 29 '15 at 20:04
  • You're right, my bad. Just copied the current working piece of code where i dont use the ISNULL function. Now you can see it in the Select parameter of the EntityDataSource. – Kitinz Jan 30 '15 at 10:18
  • Anyway, the strange behaviour happens when im not using the ISNULL function. If the Name column is NULL, the whole FullTaskName also become NULL even though the ID always have a value. – Kitinz Jan 30 '15 at 11:25
  • 1
    That's a standard way SQL deals with NULL propagation. It seems counterintuitive if you're used to nulls in other languages, but it simplifies SQL a lot. See for example wikipedia for explanation and more examples: http://en.wikipedia.org/wiki/Null_%28SQL%29#String_concatenation – Honza Brestan Jan 30 '15 at 11:51

0 Answers0