Can i get entity filled via Entity SQL?
Can i do something like that: I got some entity Customer with Id, Name, Comment
Now i want to get this entity from context with filled id and Name and Comment must be empty. I don't want to query it from database.
in T-SQL it simply:
Select Id, Name from Customers where id=4
Can i do that trick with Entity SQL something like that:
Select Customer.Id, Customer.Name from MyContext.Customer开发者_如何学Go Where Customer.Id=4
If I understand your questions correctly you want to do this
from c in db.Customers where c.Id == 4 select {c.Id, c.Name};
this will only select the Id
and Name
properties from the Database
Edit
so like you mentioned in your comments you need something that selects into a new customer object, you really can't do this in a single statement. You can however do something like.
var selectedCustomers = (from c in MyContext.Customers where c.Id == 4 select {c.Id, c.Name};
foreach(Customer currentCustomer in selectedCustomer)
{
Customer newCustomer = new Customer;
newCustomer.Id = currentCustomer.Id;
newCustomer.Name = currentCustomer.Name;
}
精彩评论