예제 #1
0
 public PuzzleGroup(Classroom classroom, string name)
 {
     Classroom = classroom;
     Name      = name;
 }
예제 #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 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.All(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();
        }