-
Notifications
You must be signed in to change notification settings - Fork 97
Support saving GUID values to STRING columns #273
Comments
@RonFrick this is already possible by calling Example: var guid = Guid.NewGuid();
var save = conn.CreateCommand();
save.CommandText = "INSERT INTO tbl VALUES (@p1)";
save.Parameters.AddWithValue("@p1", guid.ToString());
save.ExecuteNonQuery(); Full example: https://gist.github.com/natemcmaster/db14848ed53ae520e8a2b8a6c4410d52 |
Hey thanks Nate! I am using EF core. Is there anyway to do the same thing using DbContext? If not then I will certainly look at re writing my inserts manually and not use EF. Thanks again for the help. |
Would there be something I can do in this class to always force it to save guids as text. I already have my own version of this dll to solve other problems so I am fine for a one off fix on this issue as well. Any help is appreciated. Thanks Nate. |
You would need to change your properties CLR type to System.String instead of System.Guid. EF wraps this layer with its own type mapping, but doesn't have any influence on how the CLR types are persisted by Microsoft.Data.Sqlite. Curious, why do you need to save as TEXT instead of the default ( which BLOB)?
There are several different ways it could be done if you want the change the default behavior in your fork. One place to look is binding in SqliteParameter.cs. |
Sure would be nice to just do this.
|
Yes, when we implement this, we'll enable setting |
Note to implementor: EF Core generates |
Marking for re-triage. Given the complexities involved regarding my previous comment; I'm not sure we should ever do this. |
To state the obvious: the workaround is to pass the the values to the provider as |
Our philosophy so far has been to be highly compatible on reads, but highly predictable on writes. We support many formats when reading Adding this feature would change that. Imagine a higher-level framework (like EF Core) that generates SQL. It may generate statements like the following. SELECT $someGuidParam = x'SOME_BLOB_VALUE';
-- or
SELECT * FROM MyTable
WHERE SomeGuidColumn = x'SOME_BLOB_VALUE'; As it stands now, these will always work. However, if we allow changing the format of Guid values based on an application-defined parameter, the SQL would need to react by inserting Give the complexities this would introduce into frameworks that leverage Microsoft.Data.Sqlite, we've decided that we would not like to add this feature. |
Need a way to specify saving guid as text column. I would think adding a way to set BinaryGUID to false in the connection string would solve the issue.
The text was updated successfully, but these errors were encountered: