I have a legacy application which contains a Class called CustomerInvoice
. I need to relate these items to database tables which have less than friendly names (for example there is CUSTOMER_INV_HEAD
, CUST_INV_LINES
, CUST_INV_POSTS
, and potentially many others).
First attempt was inheriting interfaces for the internal names and then use getters and setters to place the correct data in respective tables, the issue here is that the logic lives in the wrong layer of my application, and it all needs to be public which is not desirable - nevermind the maintenance aspect!
I have read lots about ORM and thought that AutoMapper may work but most of the examples that I have seen demonstrate where the names either side are the same. I also reviewed NHibernate which seems similar.
I need to do something like this:
public class CustomerInvoice
{
public string id; // lives in CUSTOMER_INV_HEAD
public decimal netTotal; // lives in CUSTOMER_INV_HEAD called NET_INV_TOTAL
public IEnumerable<InvoiceLine> Lines; // collection of CUST_INV_LINES but including the id
}
So what i need to be able to do is say...
List<CUST_INV_LINES> l = Map<CustomerInvoice.Lines, CUST_INV_LINES>();
But how can i define that relationship in a clever, maintainable way without hand coding the relationships in special methods?