Controlling DBML EntityRef creation in DBML with multiple foreign keys

900 Views Asked by At

Using Linq to SQL and the autogeneration capabilities of DBML, foreign key relationships create EntityRefs in the DBML designer file. For example :

private int _USStateId;

private EntityRef<USState> _USState;

However, if I have the need for a table with numerous FK relationships to the same table, how can i control the autogenerated names? For example, for a Car survey with three FKs into a Ratings table, I get

private int _BodyRatingId;
private int _ColorRatingId;
private int _PerformanceRatingId;

in my Car table with

private EntityRef<Rating> _Rating;
private EntityRef<Rating> _Rating1;
private EntityRef<Rating> _Rating2;

How can I, dynamically or other wise, control the EntityRef naming to indicate that they pertain to a particular field?

Thanks!

1

There are 1 best solutions below

0
On BEST ANSWER

Hi I'm not sure if the question is still valid but in case anybody needs it:

You can add a partial class to your project with the same name as your Car table and add new properties:

public Rating BodyRating
    {
        get
        {
            return this._Rating.Entity;
        }
    }