I was given a few dozen legacy SQL statements that are each hundred(s) of lines long. Each SQL is mapped to code with its own unique POCO in a shared Models
project.
For example, the SQL Select Name, Birthday From People
has an equivilent POCO in the Models
project:
public class BirthdayPerson : SqlResultBase {
public string Name { get; set; }
public datetime Birthday { get; set; }
//SqlResultBase abstraction:
public string HardcodedSql { get {
return "Select Name, Birthday From People";
}}
}
In my DAL, I have a single generic SQL runner whose <T>
represents the POCO for the SQL. So my business logic can call GetSqlResult<BirthdayPerson>()
:
public IEnumerable<T> GetSqlResult<T>() where T : SqlResultBase, new() {
return context.Database.SqlQuery<T>((new T()).HardcodedSql);
}
The problem is that my Models
library is used across the application, and I don't want SQL exposed across the application in that HardcodedSql property.
This is the architecture I'm using: