本文整理汇总了C#中DbContextOptionsBuilder.UseSqlite方法的典型用法代码示例。如果您正苦于以下问题:C# DbContextOptionsBuilder.UseSqlite方法的具体用法?C# DbContextOptionsBuilder.UseSqlite怎么用?C# DbContextOptionsBuilder.UseSqlite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbContextOptionsBuilder
的用法示例。
在下文中一共展示了DbContextOptionsBuilder.UseSqlite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnConfiguring
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
optionsBuilder.UseSqlite($"Data Source={databaseFile};");
optionsBuilder.EnableSensitiveDataLogging();
}
示例2: OnConfiguring
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
#if UNIT_TEST
optionsBuilder.UseSqlite("Filename=PodcastsTests.db");
#else
optionsBuilder.UseSqlite("Filename=Podcasts.db");
#endif
}
示例3: OnConfiguring
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
SqliteConnectionStringBuilder sb = new SqliteConnectionStringBuilder();
sb.DataSource = filename;
optionsBuilder.UseSqlite(sb.ToString());
}
示例4: It_enforces_foreign_key
public void It_enforces_foreign_key(bool suppress)
{
var builder = new DbContextOptionsBuilder();
var sqliteBuilder = builder.UseSqlite(_testStore.Connection.ConnectionString);
if (suppress)
{
sqliteBuilder.SuppressForeignKeyEnforcement();
}
var options = builder.Options;
using (var context = new MyContext(options))
{
context.Database.EnsureCreated();
context.Add(new Child { ParentId = 4 });
if (suppress)
{
context.SaveChanges();
}
else
{
var ex = Assert.Throws<DbUpdateException>(() => { context.SaveChanges(); });
Assert.Contains("FOREIGN KEY constraint failed", ex.InnerException.Message);
}
}
}
示例5: It_allows_foreign_key_to_unique_index
public void It_allows_foreign_key_to_unique_index()
{
var builder = new DbContextOptionsBuilder();
var sqliteBuilder = builder.UseSqlite(_testStore.Connection.ConnectionString);
var options = builder.Options;
_testStore.ExecuteNonQuery(@"
CREATE TABLE User (
Id INTEGER PRIMARY KEY,
AltId INTEGER NOT NULL UNIQUE
);
CREATE TABLE Comment (
Id INTEGER PRIMARY KEY,
UserAltId INTEGER NOT NULL,
Comment TEXT,
FOREIGN KEY (UserAltId) REFERENCES User (AltId)
);");
long id;
using (var context = new BloggingContext(options))
{
var entry = context.User.Add(new User { AltId = 1356524 });
context.Comments.Add(new Comment { User = entry.Entity });
context.SaveChanges();
id = entry.Entity.Id;
}
using (var context = new BloggingContext(options))
{
var comment = context.Comments.Include(u => u.User).Single();
Assert.Equal(id, comment.User.Id);
}
}
示例6: Main
public static void Main(string[] args)
{
Logger.Info("Update Batch Starting");
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables();
Configuration = builder.Build();
DbContextOptionsBuilder<BddContext> options = new DbContextOptionsBuilder<BddContext>();
options.UseSqlite(Program.Configuration["Data:DefaultConnection:ConnectionString"]);
Options = options.Options;
string[] equipe = new string[] { "equipe1", "equipe2", "equipe3"};
// Parsing classement
ParseClassement(equipe);
// Parsing des actualités
ParseActus();
// Parsing des pages Agendas
ParseAgendas();
// Parsing des pages par journées
ParseJournees();
Logger.Info("Update Batch End");
}
示例7: OnConfiguring
//Add-Migration vyzva-sqlite-001 -c NewData.Vyzva57Context_Sqlite
//Update-Database vyzva-sqlite-001 -c NewData.Vyzva57Context_Sqlite
protected override void OnConfiguring(DbContextOptionsBuilder options) {
base.OnConfiguring(options);
var config = ConfigurationManager.ConnectionStrings["Vyzva57-sqlite"];
var conn = new SqliteConnection(config.ConnectionString);
//var conn = new SqliteConnection("Data Source=" + MachinesLow.rootDir + config.ConnectionString);
options.UseSqlite(conn);
}
示例8: OnConfiguring
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlite("Filename=Notes.db");
}
}
示例9: InheritanceSqliteFixture
public InheritanceSqliteFixture()
{
_serviceProvider
= new ServiceCollection()
.AddEntityFramework()
.AddSqlite()
.ServiceCollection()
.AddSingleton(TestSqliteModelSource.GetFactory(OnModelCreating))
.AddInstance<ILoggerFactory>(new TestSqlLoggerFactory())
.BuildServiceProvider();
var testStore = SqliteTestStore.CreateScratch();
var optionsBuilder = new DbContextOptionsBuilder();
optionsBuilder.UseSqlite(testStore.Connection);
_options = optionsBuilder.Options;
// TODO: Do this via migrations & update pipeline
testStore.ExecuteNonQuery(@"
DROP TABLE IF EXISTS Country;
DROP TABLE IF EXISTS Animal;
CREATE TABLE Country (
Id int NOT NULL PRIMARY KEY,
Name nvarchar(100) NOT NULL
);
CREATE TABLE Animal (
Species nvarchar(100) NOT NULL PRIMARY KEY,
Name nvarchar(100) NOT NULL,
CountryId int NOT NULL ,
IsFlightless bit NOT NULL,
EagleId nvarchar(100),
'Group' int,
FoundOn tinyint,
Discriminator nvarchar(255),
FOREIGN KEY(countryId) REFERENCES Country(Id),
FOREIGN KEY(EagleId) REFERENCES Animal(Species)
);
CREATE TABLE Plant (
Genus int NOT NULL,
Species nvarchar(100) NOT NULL PRIMARY KEY,
Name nvarchar(100) NOT NULL,
CountryId int,
HasThorns bit,
FOREIGN KEY(countryId) REFERENCES Country(Id)
);
");
using (var context = CreateContext())
{
SeedData(context);
}
TestSqlLoggerFactory.Reset();
}
示例10: OnConfiguring
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
spath = AppDomain.CurrentDomain.GetData("DataDirectory").ToString() + "\\" + "database.sqlite";
optionsBuilder.UseSqlite("Data Source=" + spath);
base.OnConfiguring(optionsBuilder);
}
示例11: OnConfiguring
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var connectionStringBuilder = new SqliteConnectionStringBuilder {DataSource = "test.db"};
var connectionString = connectionStringBuilder.ToString();
var connection = new SqliteConnection(connectionString);
optionsBuilder.UseSqlite(connection);
}
示例12: EntitiesTests
public EntitiesTests()
{
var builder = new DbContextOptionsBuilder();
builder.UseSqlite($"Filename=DynamicLinqTestDb_{Guid.NewGuid()}.db");
_context = new BlogContext(builder.Options);
_context.Database.EnsureDeleted();
_context.Database.EnsureCreated();
}
示例13: OnConfiguring
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = "MQTTRawData.db" };
var connectionString = connectionStringBuilder.ToString();
var connection = new SqliteConnection(connectionString);
Debug.WriteLine($"Connecting to:{connection.ConnectionString}");
optionsBuilder.UseSqlite(connection);
}
示例14: OnConfiguring
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var connStringBuilder = new SqliteConnectionStringBuilder
{ DataSource = Path.Combine(_appEnv.ApplicationBasePath, _data.Configuration["App:DbFile"]) };
var connString = connStringBuilder.ToString();
var conn = new SqliteConnection(connString);
optionsBuilder.UseSqlite(conn);
}
示例15: Can_add_extension_with_ambient_transaction_warning_suppressed
public void Can_add_extension_with_ambient_transaction_warning_suppressed()
{
var optionsBuilder = new DbContextOptionsBuilder();
optionsBuilder.UseSqlite("Database=Crunchie").SuppressAmbientTransactionWarning();
var extension = optionsBuilder.Options.Extensions.OfType<SqliteOptionsExtension>().Single();
Assert.Equal(false, extension.ThrowOnAmbientTransaction);
}