I have a class Department
.
Deparment
has one property called Address
.
I have a SQL table called Deparment
.
This Department
has 2 columns Address1
and Address2
.
I use Dapper.net and would like to put the two SQL table columns into the one property of my class.
How ? Thank!
I would do:
public class Department {
public string Address1 {get;set;}
public string Address2 {get;set;}
public string Address {
get { return Address1 + Environment.NewLine + Address2; }
}
}
Are you using this for "Read-Only". How would you expect your ORM to write the data back to the database ?
If it is read-only, instead of querying the table directly, you could wrap it in a view.
CREATE VIEW DepartmentView
(
SELECT Address1 + ', ' + Address2 as Address FROM Department
)
and then just map the view instead.