日期:2014-05-20  浏览次数:21175 次

使用 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);
                        }