public virtual IExecutableQuery <IEnumerable <T> > CreateSequenceQuery <T> (
            string id,
            StorageProviderDefinition storageProviderDefinition,
            QueryModel queryModel,
            IEnumerable <FetchQueryModelBuilder> fetchQueryModelBuilders)
        {
            ArgumentUtility.CheckNotNullOrEmpty("id", id);
            ArgumentUtility.CheckNotNull("storageProviderDefinition", storageProviderDefinition);
            ArgumentUtility.CheckNotNull("queryModel", queryModel);
            ArgumentUtility.CheckNotNull("fetchQueryModelBuilders", fetchQueryModelBuilders);

            var sqlQuery = _sqlQueryGenerator.CreateSqlQuery(queryModel);
            var command  = sqlQuery.SqlCommand;

            var queryType = sqlQuery.SelectedEntityType != null ? QueryType.Collection : QueryType.Custom;
            var query     = CreateQuery(id, storageProviderDefinition, command.CommandText, command.Parameters, queryType);

            if (queryType == QueryType.Collection)
            {
                var selectedEntityClassDefinition = _mappingConfiguration.GetTypeDefinition(sqlQuery.SelectedEntityType);
                Assertion.IsNotNull(selectedEntityClassDefinition, "We assume that in a re-store LINQ query, entities always have a mapping.");

                var fetchQueries = CreateEagerFetchQueries <T> (selectedEntityClassDefinition, fetchQueryModelBuilders);
                foreach (var fetchQuery in fetchQueries)
                {
                    query.EagerFetchQueries.Add(fetchQuery.Item1, fetchQuery.Item2);
                }

                return(new DomainObjectSequenceQueryAdapter <T> (query));
            }
            else
            {
                if (fetchQueryModelBuilders.Any())
                {
                    throw new NotSupportedException("Only queries returning DomainObjects can perform eager fetching.");
                }

                var projection = sqlQuery.SqlCommand.GetInMemoryProjection <T>().Compile();
                return(new CustomSequenceQueryAdapter <T> (query, qrr => projection(new QueryResultRowAdapter(qrr))));
            }
        }
Esempio n. 2
0
 private ObjectID CreateObjectID(Type classType, Guid id)
 {
     return(new ObjectID(_mappingConfiguration.GetTypeDefinition(classType), id));
 }