Thursday 18 October 2012

EntityDataSource - SQL Equivilent To Join, Include, Where

I was trying to get my [tbl_users] table related to my news table in order to return the username as opposed to the id.

After lots of messing about, I finally found how to do this with the following method:

DefaultContainerName="NewsEntities1" EnableFlattening="False" EntitySetName="tbl_News"
Include="tbl_Users" Where="it.Category_ID = @CategoryID">




When outputt to a control you will need to use something along the lines of the related data, everything else you can reference as normal with eval:

By <%# Eval("tbl_Users.User_Displayname")%>

To give you more of an idea of the database structure, here is a screenshot:

I will try to elaborate further in the future, but unfortunatley I am extremely busy lately.

Hope this helps as I know it was driving me up the wall at one point.


No comments: