3

I'm trying to get Items that has at least 1 Chart, Items and Charts have a 1 to many relation.

I tryed this :

<asp:EntityDataSource ID="EntityDataSource1" ContextTypeName="Entities"
EntitySetName="Items" Where="Count(it.ItemCharts) > 0" runat="server" />

But i get the error message :

No overload of canonical aggregate function 'Edm.Count' is compatible with the arg...

How do I do this without using code behind?

Thanks for the help!

JoRouss
  • 2,864
  • 2
  • 22
  • 40
  • I found a [similar question](http://stackoverflow.com/questions/6917481/how-to-add-count-of-child-table-in-entitydatasource), but it is not answered :/ – JoRouss Mar 12 '12 at 18:56

1 Answers1

4

You should use EXISTS to determine whether a collection/association is empty:

<asp:EntityDataSource ID="EntityDataSource1" ContextTypeName="Entities"
EntitySetName="Items" Where="EXISTS(it.ItemCharts)" runat="server" />
nemesv
  • 138,284
  • 16
  • 416
  • 359
  • Works! For my knowledge, what if I wanted Items that have at least 2 charts? – JoRouss Mar 13 '12 at 12:10
  • 1
    In theory you need to write `Where="(SELECT COUNT(0) FROM it.Charts) > 2"` but it seems it's not supported. See also [this table](http://msdn.microsoft.com/en-us/library/bb896323.aspx) for supported comparisons. – nemesv Mar 13 '12 at 13:14