2

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!

Gert Arnold
  • 105,341
  • 31
  • 202
  • 291
Ash Machine
  • 9,601
  • 11
  • 45
  • 52
  • I just stumbled accross this question. I asked a very similar question yesterday and got an answer. See http://stackoverflow.com/questions/6471330/is-there-any-way-to-control-the-names-of-properties-generated-by-the-linq-to-sql – Matthew Jun 25 '11 at 14:29

1 Answers1

1

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;
        }
    }
Gregosh
  • 26
  • 2