Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Best practice on Foreign Keys
Message
De
19/02/2009 07:59:50
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
18/02/2009 15:45:46
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Versions des environnements
Environment:
ASP.NET
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01382748
Message ID:
01382848
Vues:
52
Hi Shawn,

>When retrieving a record with a foreign key field it is desirable to display a field from the Primary Key table.
>
>What is the best practice for doing this using the MM.Net framework?
>
>I modified the MM.Net generated stored procedure and Data Access Layer to retrieve the desired field. Is this the acceptable method?
>
>Example:
>
>Crew table:
> CrewPK
> Name
> CrewTypeFK
> .
>
>CrewType table:
> CrewTypePK
> TypeName
> .
>
>When I display the Crew table information I want to show the CrewType.TypeName instead of the Crew.CrewTypeFK value.

In your first comment you mention it is desireable to *display* a field from the primary key table. There are of course different ways to do this. The question seems a bit opposite to me as I would normally display my primary table data along with displaying a field from the table child data. In the case you mentioned where you would be displaying data from the Crew Table along with the related TypeName field from the CrewType table. This is pretty normal behavior and is shown in the jump starts with Employee and Shipper tables. If the data is to be editable, then creating the relation between the business objects as in the jump start makes the most sense and allows the user to edit which CrewType is associated with the record.

On the other hand if the data is only for display, personally I would do it pretty much the same, but you could as you say add it to the stored procedure to just return the related record field where the childPK is equal to the parentFK. This would only give you display capability.
I hope that answers your question.
Tim
Timothy Bryan
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform