使用 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);
}
query.Where(where);
}
List<T> result = query.ToList<T>();
return result;
}
}
catch (Exception e)
{
throw e;
}
}
public List<Users> GetUsersByParam(List<string> qqList, string sex = "", string ages = "", string zodica = "", string constellation = "", string blood = "", string location = "", string greedyLoad = "")
{
var esp = DynamicLinqExpressions.True<users>();
esp.And(o => qqList.Contains(o.qq));
if (!string.IsNullOrEmpty(sex))
esp = esp.And(o => o.sex.Equals(sex));
if (!string.IsNullOrEmpty(ages))
esp = esp.And(o => o.ages.Equals(ages));
if (!string.IsNullOrEmpty(zodica))
esp = esp.And(o => o.zodiac_signs.Equals(zodica));
if (!string.IsNullOrEmpty(constellation))
esp = esp.And(o => o.constellation.Equals(constellation));
if (!string.IsNullOrEmpty(blood))
esp = esp.And(o => o.blood_type.Equals(blood));
if (!string.IsNullOrEmpty(location))
esp = esp.And(o => o.sex.Equals(location));
AbstraceDao<users> dao = new AbstraceDao<users>();
List<users> result = dao.FindListByExpression(esp,greedyLoad);
return result;
}