コード例 #1
0
        static async Task Main(string[] args)
        {
            try
            {
                EntityFrameworkProfiler.Initialize();

                var config = Devart.Data.Oracle.Entity.Configuration.OracleEntityProviderConfig.Instance;
                config.CodeFirstOptions.UseNonUnicodeStrings = true;
                config.CodeFirstOptions.UseNonLobStrings     = true;

                var builder = new ConfigurationBuilder()
                              .SetBasePath(Directory.GetCurrentDirectory())
                              .AddJsonFile("appsettings.development.json", optional: false, reloadOnChange: true);
                var configuration = builder.Build();
                EntityContext.ConnectionString = ComposeConnectionString(configuration);

                using (var scope = new TransactionScope(
                           TransactionScopeOption.Required,
                           new TransactionOptions {
                    IsolationLevel = IsolationLevel.ReadCommitted
                },
                           TransactionScopeAsyncFlowOption.Enabled))
                {
                    using (var context = new EntityContext())
                    {
                        context.Database.EnsureDeleted();
                        context.Database.ExecuteSqlCommand(@"
CREATE TABLE CLASSROOM
(
    ID          NUMBER (19, 0) GENERATED ALWAYS AS IDENTITY NOT NULL,
    NAME        VARCHAR2(50 CHAR)
)");

                        context.Database.ExecuteSqlCommand(@"
CREATE TABLE PUZZLE_GROUP
(
    ID            NUMBER (19, 0) GENERATED ALWAYS AS IDENTITY NOT NULL,
    NAME        VARCHAR2(50 CHAR),
    CLASSROOM_ID  NUMBER (19, 0) NOT NULL
)");

                        context.Database.ExecuteSqlCommand(@"
CREATE TABLE PUZZLE
(
    ID              NUMBER (19, 0) GENERATED ALWAYS AS IDENTITY NOT NULL,
    PUZZLE_GROUP_ID NUMBER (19, 0) NOT NULL,
    COMPLETED       NUMBER (1, 0) NOT NULL
)");

                        var classroom    = new Classroom("test");
                        var puzzleGroup1 = new PuzzleGroup(classroom, "group1");
                        var puzzleGroup2 = new PuzzleGroup(classroom, "group2");

                        var puzzle1 = new Puzzle(puzzleGroup1, true);
                        var puzzle2 = new Puzzle(puzzleGroup1, true);
                        var puzzle3 = new Puzzle(puzzleGroup2, true);
                        var puzzle4 = new Puzzle(puzzleGroup2, false);

                        context.Add(classroom);
                        context.Add(puzzleGroup1);
                        context.Add(puzzleGroup2);
                        context.Add(puzzle1);
                        context.Add(puzzle2);
                        context.Add(puzzle3);
                        context.Add(puzzle4);
                        await context.SaveChangesAsync();
                    }

                    scope.Complete();
                }

                using (var context = new EntityContext())
                {
                    // This works
                    var classroomResult1 = context
                                           .Set <Classroom>()
                                           .FirstOrDefault(_ => _.PuzzleGroups.Any(gr => gr.Puzzles.Any(p => p.Completed)));

                    // This doesn't - throws ORA-00936: missing expression
                    var classroomResult2 = context
                                           .Set <Classroom>()
                                           .FirstOrDefault(_ => _.PuzzleGroups.All(gr => gr.Puzzles.All(p => p.Completed)));
                }

                Console.WriteLine("Finished.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            Console.ReadKey();
        }
コード例 #2
0
        static async Task Main(string[] args)
        {
            try
            {
                EntityFrameworkProfiler.Initialize();

                var config = Devart.Data.Oracle.Entity.Configuration.OracleEntityProviderConfig.Instance;
                config.CodeFirstOptions.UseNonUnicodeStrings = true;
                config.CodeFirstOptions.UseNonLobStrings     = true;

                var builder = new ConfigurationBuilder()
                              .SetBasePath(Directory.GetCurrentDirectory())
                              .AddJsonFile("appsettings.development.json", optional: false, reloadOnChange: true);
                var configuration = builder.Build();
                EntityContext.ConnectionString = ComposeConnectionString(configuration);

                using (var scope = new TransactionScope(
                           TransactionScopeOption.Required,
                           new TransactionOptions {
                    IsolationLevel = IsolationLevel.ReadCommitted
                },
                           TransactionScopeAsyncFlowOption.Enabled))
                {
                    using (var context = new EntityContext())
                    {
                        context.Database.EnsureDeleted();
                        context.Database.ExecuteSqlCommand(@"
CREATE TABLE RIDER
(
    ID          NUMBER (19, 0) GENERATED ALWAYS AS IDENTITY NOT NULL,
    MOUNT       VARCHAR2 (100 CHAR) NOT NULL,
    COMMENT2    CLOB
)");

                        context.Database.ExecuteSqlCommand(@"
CREATE TABLE SWORD
(
    ID              NUMBER (19, 0) GENERATED ALWAYS AS IDENTITY NOT NULL,
    RIDER_ID        NUMBER (19, 0) NOT NULL,
    SWORD_TYPE      VARCHAR2 (100 CHAR) NOT NULL
)");

                        var rider = new Rider(EquineBeast.Mule);
                        rider.Comment = string.Join("", Enumerable.Range(1, 5000).Select(_ => "a"));
                        context.Add(rider);
                        await context.SaveChangesAsync();

                        rider.PickUpSword(new Sword(SwordType.Katana));
                        rider.PickUpSword(new Sword(SwordType.Longsword));
                        await context.SaveChangesAsync();
                    }

                    scope.Complete();
                }

                using (var context = new EntityContext())
                {
                    var parameter = EquineBeast.Mule;
                    var rider     = context.Set <Rider>()
                                    .Where(_ => _.Mount == parameter &&
                                           _.Swords.Any(sword => sword.SwordType == SwordType.Longsword))
                                    .Include(_ => _.Swords).FirstOrDefault();
                    //var rider = context.Set<Rider>().Where(_ => _.Mount == EquineBeast.Mule).FirstOrDefault();
                }

                Console.WriteLine("Finished.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            Console.ReadKey();
        }