开发者

How to get to the next level of Assocation in an EF4 EntityDataSource?

开发者 https://www.devze.com 2023-02-15 03:02 出处:网络
I\'ve used EF4 EntityDataSources to do DataBinding with success, but here\'s a case where I\'m stumped:

I've used EF4 EntityDataSources to do DataBinding with success, but here's a case where I'm stumped:

Table "CurrentComplaintsByUsers" has a foreign key over to a "Complaints" table. So in EF, I can access a CurrentComplaintByUser record, and navigate to its parent complaint like so:

var ccU = dataContext.CurrentComplaintsByUsers.First();
var parentComplaint = ccU.Complaint;

When I whip up an EntityDataSource based on CurrentComplaintsByUsers to bind a gridview, I want to get over from the "Complaint" object to an Assocation of Complaint called "Status". Here's a StatusID in my Complaint table, and so in code I can hit a complaint's status like so, including the Status properties:

string statusLabel = parentComplaint.Status.LabelText;

FAILURE: when I try to bake this all into an EntityDataSource, I can't get from my starting item "CurrentComplaintsByUsers" over to "Status". Here's my EDS:

<asp:EntityDataSource ID="edsCurrentCases" runat="server" 
     ConnectionString="name=EOCaseDataModel" DefaultContainerName="EOCaseDataModel" 
     EnableFlattening="False" EntitySetName="CurrentComplaintsByUsers" 
     Include="Complaint, Status">
</asp:EntityDataSource>

My error is this:

System.InvalidOperationException
"A specified Include path is not valid. 
The EntityType 'EOCaseApp.CurrentComplaintsByUser' does not declare a navigation property with the name 'Status'."

I'm trying to get to the point where this works in my Gridview:

<%# ((Current开发者_运维技巧ComplaintsByUser)Container.DataItem).Complaint.Status.LabelText %>

So, using declaritive markup only, how do I get to a related objects associations from the EDS? (I can do it in code, just trying to use the EDS exclusively when I can)

Other notes: if I remove "Status" from the "Include" in the EDS, then I get a NULL ERROR when it hits ..Complaint.Status.LabelText in my Gridview, pretty much what you'd expect.


Try changing Include="Complaint, Status" to Include="Complaint, Complaint.Status" in your EntityDataSource

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号