If there’s a better way to do this, let me know, but this is kind of how i envisioned it. Can it be done?
Customer is a table in the database/datacontext. What I want is to query that table and build a new object with it.
If i were to insert a record, I would do something like this:
Customer cust = new Customer(){ FirstName = "A", LastName = "B", Age = 31 }
db.Customers.InsertOnSubmit(cust);
db.SubmitChanges();
What I want to do is instantiate that object with a query result. Something like this:
var query =
from a in db.Customers
where a.FirstName == "A"
select a;
Customer cust = new Customer(){ query };
or maybe even
Customer cust = new Customer(){
from a in db.Customers
where a.FistName == "A"
select a;
}
is there some way to do this?
yes, like this:
you can also make totally anonymous objects as well…