0
我們的實體模型有這樣的static
屬性的想法有什麼問題?在實體框架中訪問模型
public class Repository{
private static KiaNetEntities entities = null;
public static KiaNetEntities{
get{ return entities; }
}
static Repository(){
entities = new KiaNetDbEntities();
}
}
,並使用它像這樣:
public static Customers[] GetCustomers(){
var q = from c in KiaNetEntities.Customers where c.Activated select c;
return q.ToArray();
}
public static Customers[] AddToCustomerSalary(int customerId, decimal newValue){
var q = from c in KiaNetEntities.Customers
where c.Activated && c.ID == customerId
select c;
if(q.Count() > 0){
var customer = q.First();
customer.Salary += newValue;
KiaNetEntities.SaveChanges();
}
}
不知道你的問題是什麼。爲什麼「GetCustomers」和「AddToCustomerSalary」方法是靜態的? – IndigoDelta 2011-05-30 12:45:48