private LinqToDBDomainContext CreateDomainContext(StorageMappingDescriptor storageMappingDescriptor)
        {
            var linqToDbModel = _linqToDbModelFactory.Create(storageMappingDescriptor.EntityContainerName);

            var connections = Connections.GetOrAdd(
                storageMappingDescriptor.ConnectionStringIdentity,
                connectionStringIdentity =>
            {
                var dataProvider     = new SQLiteDataProvider();
                var connectionString = _connectionStringSettings.GetConnectionString(connectionStringIdentity);
                var connection       = (SQLiteConnection)dataProvider.CreateConnection(connectionString);
                connection.Open();

                var dataConnection = new DataConnection(dataProvider, connection)
                {
                    CommandTimeout = linqToDbModel.QueryExecutionTimeout,
                    IsMarsEnabled  = false
                };
                dataConnection.AddMappingSchema(linqToDbModel.MappingSchema);

                return(Tuple.Create(connection, TuneConnection(dataConnection)));
            });

            return(new LinqToDBDomainContext(connections.Item1,
                                             connections.Item2,
                                             new ManagedConnectionStateScopeFactory(),
                                             new WritingStrategyFactory(),
                                             linqToDbModel.TransactionOptions,
                                             new NullPendingChangesHandlingStrategy()));
        }
Ejemplo n.º 2
0
    public static void Main()
    {
        var dataProvider = new SQLiteDataProvider();
        var connection   = dataProvider.CreateConnection(ConnectionString);

        connection.Open();
        var dataConnection = new DataConnection(dataProvider, connection);

        dataConnection.MappingSchema.SetDataType(typeof(TimeSpan), DataType.Int64);
        dataConnection.CreateTable <Category>();
        dataConnection.GetTable <Category>()
        .DataContextInfo
        .DataContext
        .Insert(new Category
        {
            Id   = 2,
            Time = new TimeSpan(10, 0, 0)
        });

        foreach (var category in dataConnection.GetTable <Category>())
        {
            Console.WriteLine($@"Id: {category.Id}, Time: {category.Time}");
        }
    }