public static IList ExecuteDb <T, TResult>(Db.OeDataAdapter dataAdapter, DbContext dataContext, Expression <Func <IQueryable <T>, IQueryable <TResult> > > expression, out IReadOnlyList <EfInclude> includes) { var visitor = new QueryVisitor <T>(dataAdapter.EntitySetAdapters, dataContext); Expression call = visitor.Visit(expression.Body); var metadataProvider = new OdataToEntity.EfCore.OeEfCoreEdmModelMetadataProvider(dataContext.Model); var includeVisitor = new IncludeVisitor(metadataProvider, dataAdapter.IsDatabaseNullHighestValue); call = includeVisitor.Visit(call); includes = includeVisitor.Includes; return(visitor.Query.Provider.CreateQuery <TResult>(call).ToList()); }
private List <IncludeVisitor.Include> GetIncludes(Expression expression) { var includes = new List <IncludeVisitor.Include>(); var includeVisitor = new IncludeVisitor(MetadataProvider, DataAdapter.IsDatabaseNullHighestValue); includeVisitor.Visit(expression); foreach (IncludeVisitor.Include include in includeVisitor.Includes) { PropertyInfo property = include.Property; Type declaringType; if (property.DeclaringType == typeof(Category)) { declaringType = typeof(ODataClient.OdataToEntity.Test.Model.Category); } else if (property.DeclaringType == typeof(Customer)) { declaringType = typeof(ODataClient.OdataToEntity.Test.Model.Customer); } else if (property.DeclaringType == typeof(OrderItem)) { declaringType = typeof(ODataClient.OdataToEntity.Test.Model.OrderItem); } else if (property.DeclaringType == typeof(Order)) { declaringType = typeof(ODataClient.OdataToEntity.Test.Model.Order); } else if (property.DeclaringType == typeof(ShippingAddress)) { declaringType = typeof(ODataClient.OdataToEntity.Test.Model.ShippingAddress); } else if (property.DeclaringType == typeof(CustomerShippingAddress)) { declaringType = typeof(ODataClient.OdataToEntity.Test.Model.CustomerShippingAddress); } else { throw new InvalidOperationException("unknown type " + property.DeclaringType.FullName); } PropertyInfo mapProperty = declaringType.GetProperty(property.Name); if (mapProperty == null) { throw new InvalidOperationException("unknown property " + property.ToString()); } includes.Add(new IncludeVisitor.Include(mapProperty, null)); } return(includes); }
public static IList ExecuteDb <T, TResult>(Db.OeEntitySetAdapterCollection entitySetAdapters, DbContext dataContext, Expression <Func <IQueryable <T>, IQueryable <TResult> > > expression, out IReadOnlyList <IncludeVisitor.Include> includes) { var visitor = new QueryVisitor <T>(entitySetAdapters, dataContext); Expression call = visitor.Visit(expression.Body); var includeVisitor = new IncludeVisitor(); call = includeVisitor.Visit(call); includes = includeVisitor.Includes; IList fromDb = visitor.Query.Provider.CreateQuery <TResult>(call).ToList(); if (typeof(TResult) == typeof(Object)) { fromDb = ToOpenType(fromDb); } return(fromDb); }
public static IList ExecuteDb <T, TResult>(DbContext dataContext, Expression <Func <IQueryable <T>, IQueryable <TResult> > > expression) { IQueryable <T> query = GetQuerableDb <T>(dataContext); var visitor = new QueryVisitor <T>(query); Expression call = visitor.Visit(expression.Body); var includeVisitor = new IncludeVisitor(); call = includeVisitor.Visit(call); IList fromDb = query.Provider.CreateQuery <TResult>(call).ToList(); if (typeof(TResult) == typeof(Object)) { fromDb = SortProperty(fromDb); } else { SetNullCollection(fromDb, includeVisitor.Includes); } return(fromDb); }