Is it possible to use BinaryGuid=False property with Sqlite Entity Framework connection string?

Viewed 238

I am creating desktop application using Sqlite database and entity framework. For primary keys I have taken column as BLOB, I now want to store GUID as values in this column but as a text not as BLOB.

I have found a solution that if we set "BinaryGuid=False" in Sqlite connection string it automatically save data as GUID not as blob. Now I want to implement this with entity framework. Is it possible to do this with entity framework.

Here is my working ADO .net Code:

string cs = @"Data Source=MyDatabase.db;BinaryGuid=False";
var con = new SQLiteConnection(cs);
con.Open();
var cmd = new SQLiteCommand(con);
cmd.CommandText = @"INSERT INTO MyTableName (Name,IsActive,IsDeleted,CreationTime,Id) VALUES (@Name,@IsActive,@IsDeleted,@CreationTime,@Id)";
Guid _guid = Guid.NewGuid();
cmd.Parameters.AddWithValue("@Name", "Guid False Test");
cmd.Parameters.AddWithValue("@Id", _guid);
cmd.ExecuteNonQuery();
1 Answers

You can modify your App.config file by adding BinayGUID=false to your connection string located within connectionStrings, here is a sample, also you can see this:

 <connectionStrings>
    <add name="DbContext" connectionString="data source=YourDbFileName.sqlite;initial catalog=YourDbFileName;App=EntityFramework;foreign keys=true;BinaryGUID=false;" providerName="System.Data.SQLite.EF6" />
 </connectionStrings>
Related