Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 21st, 2009, 09:12 AM
Registered User
 
Join Date: Aug 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default databind problem with templateField in details view - related to entity framework

Hello all,

I have a question that must have come up before. I have a project that is based on ADO.NET and Entity Framework and I am trying to build a master/details view. Most of it works, but there is a problem I haven't been able to solve:

I need to prepopulate four fields in the details view with information - a task creation date, userID of the creating user, a boolean task flag, and the ID of the related class. Of these, two fields are foreign keys from related (and associated) tables.
The problem arises when I turn D_USER.ID and D_CLASS_SESSION.ID into template fields. In the model.edmx file, these two fields are (of course) navigation properties called D_USER and D_CLASS_SESSION respectively.
When converting these two database fields from databound controls to templateFields, the following properties are added to the respective ItemTemplates:
Code:
Text='<%# Bind("[D_USER.ID]") %>'
Code:
Text='<%# Bind("[D_CLASS_SESSION.ID]") %>'
When called, the following error is generated as the value of the property is truncated at the period:
DataBinding: '[D_CLASS_SESSION' is not a valid indexed expression.

I've found postings that recommend removing the square brackets ('[' & ']') from the statement, but that seems to break the item's connection to the database, as it causes an error on inserting or editing.

Given the nature of the entity framework, it seems to me that all navigation properties would have similar problem when used in this manner.
how do I correct this?

Thanks,
Les Berg
 
Old August 25th, 2009, 12:45 PM
Registered User
 
Join Date: Aug 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So the problem seems to be that a foreign key field will not display as a template field. I cannot for the life of me understand why this could possibly be the case, given the nature of relational database design and programming. In using Entity Framework, these fields become 'navigation properties'. I understand that Entity Framework is a new technology, but there has to be a way to use these fields in a template field, such as those found in a Form View.

Does anyone know how to do this?
 
Old August 26th, 2009, 12:19 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 227
Thanks: 1
Thanked 7 Times in 7 Posts
Default

LesBerg:

I would check the CSDL (Conceptual Schema) which holds the E-R diagram and their relationships.

Found this article, which is a tutorial on the Entity Framework. According to the article, navigation properties are the table names.

http://geekswithblogs.net/kobush/arc...amework_1.aspx

The article is short but informative.

Hope this helps.
__________________
Disclaimer: The above comments are solely the opinion of one person and not to be construed as a directive or an incentive to commit fraudulent acts.
 
Old August 26th, 2009, 12:49 PM
Registered User
 
Join Date: Aug 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks! I'll check the article out. I also discovered that I needed to add the 'include' property to the entityDataSource with a comma-delimited list of the navigation properties. So far this lets me display data correctly. I hope to have enough code completed today to see if update and insert modes work correctly.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Entity Framework And MVC geomar BOOK: Professional ASP.NET MVC 1.0 ISBN: 978-0-470-38461-9 5 January 24th, 2011 04:58 PM
Switching To entity framework luckystar BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 0 July 31st, 2009 09:52 PM
populate details view or list view non empty rows iinfoque ASP.NET 2.0 Basics 0 March 11th, 2007 06:11 AM
Problem with Details View and Multiple DataSources safin ASP.NET 2.0 Professional 1 April 23rd, 2006 01:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.