0

I have been trying Browse a sqlite db file and read data using Entity framework . But following way does not work I am initiating the MydbContext with sqlite file path eg

 using (var sourceContext = new MydbContext(@"D:\test\data.sqlite"))
            {
               var a= sourceContext.MyModel.ToList();
            }

  public MydbContext(string path)
           : base(GetConnectionString(path))
        {
            Configuration.LazyLoadingEnabled = false;
        }

 public static string GetConnectionString(string path)
        {
var entityConnectionString = new EntityConnectionStringBuilder
            {
                Metadata = "res://*",
                Provider = "System.Data.SQLite.EF6",
                ProviderConnectionString = sqlLiteConnectionString,
            }.ConnectionString;
}

Please suggest if there is a proper way to achieve this using sqlite and ef.

Thunder
  • 10,366
  • 25
  • 84
  • 114

1 Answers1

0

Got the answer from comments

 private static SQLiteConnection GetConnectionString(string path)
        {
            var con= new SQLiteConnection()
            {
                ConnectionString =
              new SQLiteConnectionStringBuilder()
              { DataSource = path, ForeignKeys = true,BinaryGUID = false }
              .ConnectionString
            };

            return con;
        }
Thunder
  • 10,366
  • 25
  • 84
  • 114