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