当前位置: 代码迷 >> .NET Framework >> 运用 Include 后 依然此 ObjectContext 实例已释放,不可再用于需要连接的操作
  详细解决方案

运用 Include 后 依然此 ObjectContext 实例已释放,不可再用于需要连接的操作

热度:403   发布时间:2016-05-01 23:53:56.0
使用 Include 后 依然此 ObjectContext 实例已释放,不可再用于需要连接的操作

    public partial class Users
    {
        public users()
        {
            this.advanced_property = new HashSet<advanced_property>();
            this.secondary_property = new HashSet<secondary_property>();
        }
    
        public int id { get; set; }
        public string qq { get; set; }
        public string sex { get; set; }
        public string ages { get; set; }
        public string zodiac_signs { get; set; }
        public string constellation { get; set; }
        public string blood_type { get; set; }
        public string location { get; set; }
    
        public virtual ICollection<advanced_property> advanced_property { get; set; }
        public virtual ICollection<secondary_property> secondary_property { get; set; }
    }

public List<T> FindListByExpression(Expression<Func<T, bool>> where, string greedyLoad = "")
        {
            try
            {

                using (context = new qqMarketingEntities1())
                {
                    var query = context.Set<T>();
                    if (!string.IsNullOrEmpty(greedyLoad))
                    {
                        List<string> greedyLoads = greedyLoad.Split(',').ToList();
                        foreach (var i in greedyLoads)
                        {
                            query.Include(i);
                        }
  相关解决方案