Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var dbFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
- var fileName = "dbappoitnemtns.db";
- var dbFullPath = Path.Combine(dbFolder, fileName);
- try
- {
- using (var db = new BookingContext(dbFullPath))
- {
- await db.Database.MigrateAsync(); //We need to ensure the latest Migration was added. This is different than EnsureDatabaseCreated.
- Appointments _appTestDate1 = new Appointments() { Subject="Test Appointment
- 1",StarDate=DateTime.Now,EndDate=DateTime.Now.AddHours(2),isActive=true };
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.ToString());
- }
- using BookingDataAccess.Models;
- using Microsoft.EntityFrameworkCore;
- namespace BookDataContext
- {
- public class BookingContext : DbContext
- {
- public DbSet<Appointments> Appointment { get; set; }
- private string DatabasePath { get; set; }
- public BookingContext()
- {
- }
- public BookingContext(string databasePath)
- {
- DatabasePath = databasePath;
- }
- protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
- {
- optionsBuilder.UseSqlite($"Filename={DatabasePath}");
- }
- }
- }
- <ItemGroup>
- <PackageReference Include="Microsoft.EntityFrameworkCore">
- <Version>2.0.2</Version>
- </PackageReference>
- <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core">
- <Version>2.0.2</Version>
- </PackageReference>
- <PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="25.*" />
- </ItemGroup>
Add Comment
Please, Sign In to add comment