我有一个错误
在 using 语句中使用的类型必须隐式转换为“System.IDisposable”
在线的
using (var context = new EntityContainer())
这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Globalization;
using System.Data;
using System.Data.Entity;
using school.usi.susibar.model;
namespace school.usi.susibar.test
{
class Program
{
public static void Main(string []args)
{
using (var context = new EntityContainer())
{
addOrderStatusType(context);
Console.ReadLine();
}
}
private static void addOrderStatusType(EntityContainer context)
{
try
{
OrderStatusType type = new OrderStatusType
{
Name = "Vyrizeno",
CancelPermission = false,
ChangePermission = false
};
context.OrderStatusTypes.Add(type);
context.SaveChanges();
Console.WriteLine("Pridano");
}
catch (Exception ex) {
Console.WriteLine(ex.InnerException);
}
}
}
}
EntityContainer() 看起来像这样......
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace school.usi.susibar.model
{
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
public partial class EntityContainer : DbContext
{
public EntityContainer()
: base("name=EntityContainer")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public DbSet<Role> Roles { get; set; }
public DbSet<Category> Categories { get; set; }
public DbSet<Table> Tables { get; set; }
public DbSet<OrderStatusType> OrderStatusTypes { get; set; }
public DbSet<Person> Persones { get; set; }
public DbSet<Item> Items { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<Stock> Stocks { get; set; }
public DbSet<ItemOrderList> ItemOrderLists { get; set; }
public DbSet<ItemOrderStatus> ItemOrderStatuses { get; set; }
public DbSet<PaymentOrderStatus> PaymentOrderStatuses { get; set; }
public DbSet<Prepaid> Prepaids { get; set; }
}
}
编辑: DbContext 实现 IDisposable 并且我无法编辑 EntityContainer() 类,因为它是从模板生成的。
有什么想法有什么问题吗?