Guest User

Untitled

a guest
Mar 24th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. var dbFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
  2. var fileName = "dbappoitnemtns.db";
  3. var dbFullPath = Path.Combine(dbFolder, fileName);
  4. try
  5. {
  6. using (var db = new BookingContext(dbFullPath))
  7. {
  8. await db.Database.MigrateAsync(); //We need to ensure the latest Migration was added. This is different than EnsureDatabaseCreated.
  9.  
  10. Appointments _appTestDate1 = new Appointments() { Subject="Test Appointment
  11. 1",StarDate=DateTime.Now,EndDate=DateTime.Now.AddHours(2),isActive=true };
  12.  
  13. }
  14. catch (Exception ex)
  15. {
  16. System.Diagnostics.Debug.WriteLine(ex.ToString());
  17. }
  18.  
  19. using BookingDataAccess.Models;
  20. using Microsoft.EntityFrameworkCore;
  21.  
  22. namespace BookDataContext
  23. {
  24. public class BookingContext : DbContext
  25. {
  26. public DbSet<Appointments> Appointment { get; set; }
  27.  
  28. private string DatabasePath { get; set; }
  29.  
  30. public BookingContext()
  31. {
  32.  
  33. }
  34.  
  35. public BookingContext(string databasePath)
  36. {
  37. DatabasePath = databasePath;
  38. }
  39.  
  40. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  41. {
  42. optionsBuilder.UseSqlite($"Filename={DatabasePath}");
  43. }
  44. }
  45. }
  46.  
  47. <ItemGroup>
  48. <PackageReference Include="Microsoft.EntityFrameworkCore">
  49. <Version>2.0.2</Version>
  50. </PackageReference>
  51. <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core">
  52. <Version>2.0.2</Version>
  53. </PackageReference>
  54. <PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="25.*" />
  55. </ItemGroup>
Add Comment
Please, Sign In to add comment