【发布时间】:2011-09-04 19:22:15
【问题描述】:
我们有这样的实体模型的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方法是静态的?
标签: c# asp.net-mvc-2 entity-framework-4 data-access-layer