I have a unique requirement that I hope is possible with LINQ to SQL.
First off, I am extending an older application so I am stuck with current database column names and the existing LINQ entity classes.
I have a LINQ wrapper with the following method:
public T Get(int id) where T : class, IEntity {
...
}
IEntity looks like:
public interface IEntity {
int Id { get; }
}
My existing entity class (generated by LINQ) looks like:
//this is not the exact code
//it is just to give you an idea
public parital class Widget {
public int WidgetId { get; set; }
public string WidgetName { get; set; }
}
So in order to make Widget work with my wrapper I extended it to be an IEntity like:
public partial class Widget : IEntity {
public int Id { get { return WidgetId; } }
}
When I do a select like:
Repository<Widget>.Get(123);
I get an error saying Id is not mapped in SQL.
What I want to know is there a way for me to make Widget an IEntity and use Id as an alias of WidgetId. There is already a lot of older code written (without the repository wrapper) that references WidgetId so I don't want to have to change this.
All suggestions are appreciated. Am I going about this wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…