Esempio n. 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 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();
        }