public IQueryable <T> GetDoubleRelation <T>(Type objectType, object id) where T : class { var type = LinqToSqlUtils.GetTableName(objectType); var requiredObjectType = LinqToSqlUtils.GetTableName(typeof(T)); var requiredRelations = GetRequiredRelationsByDoubleLink( id, type, requiredObjectType); var requiredIds = requiredRelations.Select(sor => sor.Object.ID); return(context.GetTable <T>().Where(LinqToSqlUtils.WhereContains <T>(requiredIds))); }
public IQueryable <T> GetSingleRelation <T>(string objectType, object id) where T : class { var requiredObjectType = LinqToSqlUtils.GetTableName(typeof(T)); var requiredIds = GetRequiredObjectIdsByObject(id, objectType, requiredObjectType); var objList = context.GetTable <T>().Where(LinqToSqlUtils.WhereContains <T>(requiredIds)); return(objList); }
public IQueryable <T> GetWithoutRelation <T>() where T : class { var requiredObjectType = LinqToSqlUtils.GetTableName(typeof(T)); var objectIdsWithRelations = from sor in context.GetTable <SiteObjectRelation>() where sor.ObjectType == requiredObjectType select sor.Object_ID; return(context.GetTable <T>() .Where(LinqToSqlUtils.WhereContains <T>(objectIdsWithRelations, true))); }
public IQueryable <T> GetRelation <T>(Type objectType, object id) where T : class { var type = LinqToSqlUtils.GetTableName(objectType); var requiredObjectType = LinqToSqlUtils.GetTableName(typeof(T)); var cityTC = UserSettingsService.CityTC; IQueryable <T> objList = null; var doubleLinkRelations = new List <Type> { typeof(Banner), typeof(Response), typeof(News) }; var singleLinkRelations = new List <Type> { typeof(City) }; var byRelationObject = new List <Type> { typeof(Course), typeof(Product), typeof(Certification) }; if (doubleLinkRelations.Contains(typeof(T))) { IQueryable <SiteObjectRelation> requiredRelations; if (cityTC == null) { requiredRelations = GetRequiredRelationsByDoubleLink( id, type, requiredObjectType); } else { requiredRelations = GetRequiredRelationsByRelations2WithCity( id, type, requiredObjectType, cityTC); } /* if (cityTC != null ) * requiredRelations = FilterByCity<T>(requiredRelations, * context.GetTable<SiteObjectRelation>(), cityTC);*/ var requiredIds = requiredRelations.Select(sor => sor.Object.ID); objList = context.GetTable <T>().Where( LinqToSqlUtils.WhereContains <T>(requiredIds)); } else if (singleLinkRelations.Contains(typeof(T))) { objList = GetSingleRelation <T>(objectType, id); } else if (byRelationObject.Contains(typeof(T))) { objList = GetByRelationObject <T>(objectType, id); } /* if (typeof(T) == ) * objList = (IQueryable<T>)( * from o in context.GetTable<Response>() * where context.GetTable<SiteObjectRelation>().Where( * sor => sor.Object_ID == id && sor.ObjectType == type) * .SelectMany(sor => sor.RelationObject.RelationObjectRelations) * .Where(sor => sor.Object.Type == relationObjectType) * .Select(sor => sor.Object.ID).Contains(o.ResponseId) * select o); * * if (typeof(T) == typeof(Certification)) * objList = (IQueryable<T>)( * from o in context.GetTable<Certification>() * where context.GetTable<SiteObjectRelation>().Where( * sor => sor.Object_ID == id && sor.ObjectType == type * && sor.RelationObjectType == requiredObjectType) * .Select(sor => sor.RelationObject_ID).Contains(o.Certification_ID) * select o); * */ return(objList); }