Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Entity Framework Question - Update Command

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
US
How do you handle situations where you have a foreign key in your table, something like a customer type where you want to display the description of the customer type, not the type code? I know you can edit the select statement and use a where condition and not a join to include the text, but is this the best way? It is my understanding that I cannot use a join and still be able to use the generated update command. Some of my tables have several foreign keys of this nature and some of them can be null. Do I have to use different select statements for each of these fields to display the related text or information on my detail record forms? I must be missing something basic here.

Auguy
Sylvania/Toledo Ohio
 
Not sure about Entity Framework specifically, but In ADO.Net you do this by using an expression column of the datatable. If a datarelation is established then you can create an expression column to display a related field value of a parent or child record.
 
Thanks, I will look into that. I've always hand coded my select, insert, update, etc. stored procedures. Do you have a preference as to which method you use?

Auguy
Sylvania/Toledo Ohio
 
Just depends. I am lazy so if I can have the system do it then I leverage that where I can. If you have a lot of fields and are worried about concurreny you can get some really, really long concurrency checks. You can add columns in the designer or in code.
Parent/Child Relation Referencing
A parent table may be referenced in an expression by prepending the column name with Parent. For example, the Parent.Price references the parent table's column named Price.
When a child has more than one parent row, use Parent(RelationName).ColumnName. For example, the Parent(RelationName).Price references the parent table’s column named Price via the relation.
A column in a child table may be referenced in an expression by prepending the column name with Child. However, because child relationships may return multiple rows, you must include the reference to the child column in an aggregate function. For example, Sum(Child.Price) would return the sum of the column named Price in the child table.
If a table has more than one child, the syntax is: Child(RelationName). For example, if a table has two child tables named Customers and Orders, and the DataRelation object is named Customers2Orders, the reference would be as follows:
Avg(Child(Customers2Orders).Quantity)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top