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 OTHER_RIDER
(
    ID          NUMBER (19, 0) GENERATED ALWAYS AS IDENTITY NOT NULL,
    BEAST_NAME VARCHAR2 (50 CHAR) NOT NULL,
    BEAST_TYPE VARCHAR2 (50 CHAR) NOT NULL
)");

                        var otherBeast = new Beast("Viscerion", EquineBeast.Donkey);
                        var otherRider = new OtherBeastRider(otherBeast);
                        context.Add(otherRider);

                        await context.SaveChangesAsync();
                    }

                    scope.Complete();
                }

                using (var context = new EntityContext())
                {
                    var otherRider = context
                                     .Set <OtherBeastRider>()
                                     .FirstOrDefault(_ =>
                                                     _.Beast.Name == "Viscerion" ||          // Correctly translated to SQL
                                                     _.Beast.Name.StartsWith("Viscerion") || // ERROR ORA-00904: "_.Beast"."BEAST_NAME": invalid identifier
                                                     _.Beast.Name.Contains("Viscerion") ||   // ERROR ORA-00904: "_.Beast"."BEAST_NAME": invalid identifier
                                                     _.Beast.Name.EndsWith("Viscerion")      // ERROR ORA-00904: "_.Beast"."BEAST_NAME": invalid identifier
                                                     );
                }

                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,
    BEAST_NAME VARCHAR2 (50 CHAR) NOT NULL,
    BEAST_TYPE VARCHAR2 (50 CHAR) NOT NULL,
    DISCRIMINATOR VARCHAR2 (50 CHAR) NOT NULL
)");

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

                        var beast = new Beast("Drogo", EquineBeast.Horse);
                        var rider = new BeastRider(beast);
                        context.Add(rider);

                        var otherBeast = new Beast("Viscerion", EquineBeast.Donkey);
                        var otherRider = new OtherBeastRider(otherBeast);
                        context.Add(otherRider);

                        await context.SaveChangesAsync();
                    }

                    scope.Complete();
                }

                using (var context = new EntityContext())
                {
                    // Works as expected, clean SQL
                    var otherRider = context.Set <OtherBeastRider>()
                                     .FirstOrDefault();

                    // Works, but generates unnecessary left join in SQL
                    var rider = context.Set <BeastRider>()
                                .FirstOrDefault();
                }

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

            Console.ReadKey();
        }