Пример #1
0
        private static void PerformanceCacheOeTest(SelectTestDefinition[] testDefinitions, int testCount, bool cache)
        {
            var dataAdapter = new OeEfCoreDataAdapter <OrderContext>(new Db.OeQueryCache()
            {
                AllowCache = cache
            });
            IEdmModel edmModel = dataAdapter.BuildEdmModel();
            var       parser   = new OeParser(new Uri("http://dummy"), dataAdapter, edmModel);

            GC.Collect();
            GC.WaitForPendingFinalizers();

            var stopWatch = new Stopwatch();

            stopWatch.Start();
            for (int i = 0; i < testCount; i++)
            {
                foreach (SelectTestDefinition testDefinition in testDefinitions)
                {
                    var uri = new Uri("http://dummy/" + testDefinition.Request);
                    using (var response = new MemoryStream())
                        parser.ExecuteGetAsync(uri, OeRequestHeaders.Default, response, CancellationToken.None).GetAwaiter().GetResult();
                }
            }
            stopWatch.Stop();
            Console.WriteLine("OdataToEntity cache = " + cache + " " + stopWatch.Elapsed);
        }
Пример #2
0
        public static EdmModel BuildDbEdmModel(bool useRelationalNulls)
        {
            var       orderDataAdapter  = new OeEfCoreDataAdapter <OrderContext>(Create(useRelationalNulls));
            IEdmModel orderEdmModel     = orderDataAdapter.BuildEdmModel();
            var       order2DataAdapter = new OeEfCoreDataAdapter <Order2Context>(Create <Order2Context>(useRelationalNulls));

            return(order2DataAdapter.BuildEdmModel(orderEdmModel));
        }
Пример #3
0
        private static OeParser InitParser()
        {
            var dataAdapter = new OeEfCoreDataAdapter <AppDB>();
            //Create query parser
            var parser = new OeParser(new Uri("http://localhost:5000/odata/"), dataAdapter.BuildEdmModelFromEfCoreModel());

            return(parser);
        }
        public void AlternativeKey()
        {
            var       da                = new OeEfCoreDataAdapter <MyFinanceDbContext1>();
            IEdmModel edmModel          = da.BuildEdmModelFromEfCoreModel();
            var       acct              = (IEdmStructuredType)edmModel.FindType(typeof(Acct).FullName);
            var       deptRefNavigation = acct.NavigationProperties().Single(p => p.Name == nameof(Acct.DeptRefNavigation));
            var       key               = deptRefNavigation.PrincipalProperties().Single();

            Assert.Equal(nameof(Dept.Ref), key.Name);
        }
Пример #5
0
        public void FluentApi()
        {
            var      ethalonDataAdapter = new OeEfCoreDataAdapter <OrderContext>();
            EdmModel ethalonEdmModel    = ethalonDataAdapter.BuildEdmModel();
            String   ethalonSchema      = TestHelper.GetCsdlSchema(ethalonEdmModel);

            var      testDataAdapter = new OrderOeDataAdapter(false, false, null);
            EdmModel testEdmModel    = BuildEdmModelFromEf6Model(testDataAdapter);
            String   testSchema      = TestHelper.GetCsdlSchema(testEdmModel);

            Assert.Equal(ethalonSchema, testSchema);
        }
        public static EdmModel BuildDbEdmModel(IEdmModel _, bool useRelationalNulls)
        {
            var orderDataAdapter = new OeEfCoreDataAdapter <OrderContext>(Create(useRelationalNulls))
            {
                IsDatabaseNullHighestValue = true
            };
            IEdmModel orderEdmModel     = orderDataAdapter.BuildEdmModelFromEfCoreModel();
            var       order2DataAdapter = new OeEfCoreDataAdapter <Order2Context>(Create <Order2Context>(useRelationalNulls))
            {
                IsDatabaseNullHighestValue = true
            };

            return(order2DataAdapter.BuildEdmModelFromEfCoreModel(orderEdmModel));
        }
Пример #7
0
        private static async Task TestODataQuery()
        {
            var dataAdapter = new OeEfCoreDataAdapter <AppDB>();
            //Create query parser
            var parser = new OeParser(new Uri("http://dummy"), dataAdapter.BuildEdmModelFromEfCoreModel());
            //Query
            var uri = new Uri("http://dummy/Doctors?$filter=DoctorSpecializations/any()&$expand=DoctorSpecializations($select=SpecializationId,Specialization;$expand=Specialization($select=Name))&$select=Name");
            //The result of the query
            var response = new MemoryStream();
            //Execute query
            await parser.ExecuteGetAsync(uri, OeRequestHeaders.JsonDefault, response, CancellationToken.None);

            var s = Encoding.ASCII.GetString(response.ToArray());

            Console.WriteLine(s);
        }
        private async Task <TRes> GetDataFromContextByODataFilterAsync <TContext, TRes>(string query)
            where TContext : DataContext
        {
            var dataAdapter = new OeEfCoreDataAdapter <TContext>();
            var edmModel    = dataAdapter.BuildEdmModel();
            var parser      = new OeParser(new Uri("http://dummy"), edmModel);
            var uri         = new Uri("http://dummy/Rates?$" + query);

            var response = new MemoryStream();
            await parser.ExecuteGetAsync(uri, OeRequestHeaders.JsonDefault, response, CancellationToken.None);

            var res = Encoding.UTF8.GetString(response.GetBuffer());

            var odataResult = JsonConvert.DeserializeObject <DtoODataResult <TRes> >(res);

            return(odataResult.Value);
        }
Пример #9
0
        static async Task Main(string[] args)
        {
            //Create adapter data access, where OrderContext your DbContext
            var dataAdapter = new OeEfCoreDataAdapter <AppDBContext>();
            //Create query parser
            var parser = new OeParser(new Uri("http://dummy"), dataAdapter.BuildEdmModelFromEfCoreModel());
            //Query
            var uri = new Uri("http://dummy/Doctors?$expand=ClientAppointments&$select=Name,ClientAppointments");
            //The result of the query
            var response = new MemoryStream();
            //Execute query
            await parser.ExecuteGetAsync(uri, OeRequestHeaders.JsonDefault, response, CancellationToken.None);

            var s = Encoding.ASCII.GetString(response.ToArray());

            Console.WriteLine(s);

            Console.ReadKey();
        }
Пример #10
0
        private IEdmModel BuildEdm(IApplicationBuilder app)
        {
            var optionsbuilder = new DbContextOptionsBuilder <HRPModel>();

            optionsbuilder.UseInMemoryDatabase("hrp");
            var dataAdapter = new OeEfCoreDataAdapter <HRPModel>(optionsbuilder.Options);

            return(dataAdapter.BuildEdmModel(new[] {
                typeof(HRPUser),
                typeof(IdentityUser <string>),
                typeof(IdentityUser),
                typeof(IdentityUserRole <string>),
                typeof(IdentityRole <string>),
                typeof(IdentityRoleClaim <string>),
                typeof(IdentityUserClaim <string>),
                typeof(IdentityUserLogin <string>),
                typeof(IdentityUserToken <string>),
                typeof(IdentityRole)
            }));
        }
        public static EdmModel BuildDbEdmModel(IEdmModel oeEdmModel, bool useRelationalNulls)
        {
            IEdmModel orderEdmModel;
            OeEfCoreDataAdapter <OrderContext>  orderDataAdapter;
            OeEfCoreDataAdapter <Order2Context> order2DataAdapter;

            Db.OeDataAdapter dataAdapter = oeEdmModel.GetDataAdapter(oeEdmModel.EntityContainer);
            if (dataAdapter.CreateDataContext() is DbContext dbContext)
            {
                try
                {
                    orderDataAdapter = new OeEfCoreDataAdapter <OrderContext>(CreateOptions <OrderContext>(dbContext))
                    {
                        IsDatabaseNullHighestValue = dataAdapter.IsDatabaseNullHighestValue
                    };
                    orderEdmModel     = orderDataAdapter.BuildEdmModelFromEfCoreModel();
                    order2DataAdapter = new OeEfCoreDataAdapter <Order2Context>(CreateOptions <Order2Context>(dbContext))
                    {
                        IsDatabaseNullHighestValue = dataAdapter.IsDatabaseNullHighestValue
                    };
                    return(order2DataAdapter.BuildEdmModelFromEfCoreModel(orderEdmModel));
                }
                finally
                {
                    dataAdapter.CloseDataContext(dbContext);
                }
            }

            orderDataAdapter = new OeEfCoreDataAdapter <OrderContext>(Create(useRelationalNulls))
            {
                IsDatabaseNullHighestValue = dataAdapter.IsDatabaseNullHighestValue
            };
            orderEdmModel     = orderDataAdapter.BuildEdmModelFromEfCoreModel();
            order2DataAdapter = new OeEfCoreDataAdapter <Order2Context>(Create <Order2Context>(useRelationalNulls))
            {
                IsDatabaseNullHighestValue = dataAdapter.IsDatabaseNullHighestValue
            };
            return(order2DataAdapter.BuildEdmModelFromEfCoreModel(orderEdmModel));
        }
        public void FluentApi()
        {
            var      ethalonDataAdapter = new OeEfCoreDataAdapter <OrderContext>(OrderContextOptions.Create(true));
            EdmModel ethalonEdmModel    = ethalonDataAdapter.BuildEdmModel();
            String   ethalonSchema      = TestHelper.GetCsdlSchema(ethalonEdmModel);

            if (ethalonSchema == null)
            {
                throw new InvalidOperationException("Invalid ethalon schema");
            }

            var      testDataAdapter = new OrderDataAdapter(false, false);
            EdmModel testEdmModel    = testDataAdapter.BuildEdmModelFromEf6Model();
            String   testSchema      = TestHelper.GetCsdlSchema(testEdmModel);

            if (testSchema == null)
            {
                throw new InvalidOperationException("Invalid test schema");
            }

            String fixTestSchema = FixNamesInSchema(testSchema);

            Assert.Equal(ethalonSchema, fixTestSchema);
        }
        public void ShadowProperty()
        {
            var da = new OeEfCoreDataAdapter <MyFinanceDbContext2>();

            da.BuildEdmModelFromEfCoreModel();
        }
        public void MissingDependentNavigationProperty()
        {
            var da = new OeEfCoreDataAdapter <MyFinanceDbContext1>();

            da.BuildEdmModelFromEfCoreModel();
        }