ADO.net Adding columns to entity outside DB
I had a hard time to come up with a title for this :)
I've got a WCF service hooked up to a SQL-server database. I retrieve data
from the DB using ADO.NET.
On some simple operations I just retrieve from the DB and then send back a
json representation of the EntityObjects i just fetched which works fine.
However now I'm doing a more complex fetch with a procedure. The data
retrieval works fine but the procdure itself returns more columns than the
actual EntityObject (Table) has. Take this for an example:
create table Person
{
Name,
BirthDate
}
// Retrieve Persons from DB with procedure that also calculates each
persons actual age!
public List<EntityObject> getPersons()
{
var personList = new List<EntityObject>();
var dataSet = dbContext.ExceuteProcedure("GET_PERSONS_WITH_AGE",
parameters);
var dataTable = dataSet.Tables["result"];
foreach (DataRow row in dataTable.Rows)
{
personList.Add( new PersonEntity
{
Name = (String)row["Name"],
BirthDate = (DateTime)row["BirthDate"],
// Here i want the actual age calculation result, but since
the DB-table Person does'nt have this column,
// I can't set it.
}
}
return personList;
}
Do I need to create a CustomPersonClass for this which has this extra
variable? Or can I somehow force another column into Table Person in my
ADO.NET object?
Please consider that I'm novice about ADO.NET, if you see other code
faults in my example (regarding methods of retrival as well) please let me
know.
No comments:
Post a Comment