LINQPad6 LINQ to SQL driver - self referential table

Hi, and let me congratulate you for the LINQPad6 preview, looks amazing already.

I was doing some tests on my company's database and I've noticed the following.

One of our tables contains a self referential association. Using ILSpy I can see what LINQ2Sql driver was generating as a class definition. I've stripped out the irrelevant details and it comes down to the following:

public class TheEntityName
{
[Column(IsPrimaryKey = true, DbType = "Int NOT NULL", UpdateCheck = UpdateCheck.Never)]
public int EntityId;

[Column(IsPrimaryKey = true, CanBeNull = false, DbType = "VarChar(50) NOT NULL", UpdateCheck = UpdateCheck.Never)]
public string Key;

private EntityRef _Child;
private EntityRef _TheEntityName;


[Association(Name = "FK_TheEntityName_TheEntityName", Storage = "_TheEntityName", ThisKey = "EntityId,Key", OtherKey = "EntityId,Key", IsForeignKey = true)]
public TheEntityName TheEntityName
{
get { return _TheEntityName.Entity; }
set { _TheEntityName.Entity = value; }
}

[Association(Name = "FK_TheEntityName_TheEntityName", Storage = "_Child", ThisKey = "EntityId,Key", OtherKey = "EntityId,Key", IsForeignKey = false, IsUnique = true)]
public TheEntityName Child
{
get { return _Child.Entity; }
set { _Child.Entity = value; }
}
}
I suppose that the code above is generated by the runtime directly as obviously if you tried to set up something similar in C# you would get a compile time error:
CS0542: member names cannot be the same as their enclosing type.

LINQPad6 is definitely attempting to perform the same as I can see this error when I'm trying to set up a connection.

To be absolutely fair, I'm not sure what the actual reasoning behind the association above currently is and probably I could remove it and that would solve the problem. However in a more general approach and assuming that such association is indeed necessary, is it possible to modify the driver code in order to generate a property name that does not violate CS0542?

Thanks

Comments

  • Thanks for the info. Are you able to compare it with the code that LINQPad 5 generates?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!