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:
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
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:
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:
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; }
}
}
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
The code above is the decompiled result from ILSpy from the code that LINQPad 5 generates. Unfortunately I'm not sure if I can check what LINQPad 6 generates as it fails with the error message above. However let me know if I can provide any assistance.
The following should result in the same issue. Again, I have to say that I have no idea what the foreign key is supposed to be, but it is what it is.