|
|
 |
| 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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

August 21st, 2009, 10:12 AM
|
|
Registered User
|
|
Join Date: Aug 2009
Location: Boise, Idaho
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

August 25th, 2009, 01:45 PM
|
|
Registered User
|
|
Join Date: Aug 2009
Location: Boise, Idaho
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|

August 26th, 2009, 01:19 AM
|
|
Friend of Wrox
|
|
Join Date: May 2005
Location: OKC, OK, USA.
Posts: 211
Thanks: 1
Thanked 7 Times in 7 Posts
|
|
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.
|

August 26th, 2009, 01:49 PM
|
|
Registered User
|
|
Join Date: Aug 2009
Location: Boise, Idaho
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |