Figured it out. It's the ADO.NET provider that is changing things, not NHibernate.
By default it stores guids as a binary to save space. That makes it difficult to access with 'normal' sql as I was doing. Including ";BinaryGuid=False" in the connection string changes that behavior and stores the guid as a string instead which is much easier to mess with via sql. Its less efficient but this is just a test scenario so that doesn't matter. On Mar 13, 4:52 pm, brendanjerwin <[email protected]> wrote: > Ok, the problem is absolutely that I am updating the value of the ID > column differently than NHibernate is. > There is some sort of conversion going on with the data that gets put > into Sqlite. > > This is the value that is in the database: > C74ECDE1B3241B4D84C29BCB0113448F <-Hex(Id) > > And this is the Guid value that resulted in that value. > E1CD4EC724B34D1B84C29BCB0113448F <-Guid in code > > Does anyone know what is happening to the value? What transformation > converts E1CD4EC724B34D1B84C29BCB0113448F into > C74ECDE1B3241B4D84C29BCB0113448F? > > On Mar 13, 2:23 pm, brendanjerwin <[email protected]> wrote: > > > > > Ok, its a little bit closer. > > The weird data I see in the DB is because it's a blob. > > The SQL I need to run to update the data is this: > > > UPDATE Model SET ID = X'14BD459F027B4BD39C31AEA550B9808C' > > > That results in a new weird looking blob value in the database. But, > > now when I run NHibernate still can't find the instance. NHProf tells > > me the query is: > > > WHERE model0_.ModelID = '14bd459f-027b-4bd3-9c31-aea550b9808c' /* @p0 > > */ > > > And when I run that directly against the database I do, in fact, get > > no result. If I run this though: > > > WHERE model0_.ModelID = X'14bd459f027b4bd39c31aea550b9808c' /* @p0 */ > > > I get a result. Is the problem now that NHibernate is querying for the > > uniqueidentifier wrong? Or is it fact doing it right and what NHProf > > is showing me is not what was actually executed? > > (Is there a way to profile Sqlite directly?) > > > On Mar 13, 1:37 pm, Brendan Erwin <[email protected]> wrote: > > > > I think I might have a clue here. > > > > Looking at the SQLite database before running my manual SQL I see that > > > the uniqueidentifier column contains something very different than I > > > was expecting: BSä ` BM‰µ›Ë > > > > I was expecting (and am updating the column to) something that looks > > > like a GUID: 14BD459F-027B-4BD3-9C31-AEA550B9808C > > > > My guess is that the Sqlite dialect is encoding the .NET Guid into > > > something more appropriate for Sqlite. I need to do the same when I > > > manually update the database. I'll start looking in that direction, > > > any pointers? > > > > On Mar 13, 2009, at 11:30 AM, James Gregory wrote: > > > > > These records that you're manipulating, are they inserted by NH > > > > originally? If so then NH might still be doing some caching. Have > > > > you tried a session.Refresh()? Although I don't know why that would > > > > be different to destroying it and getting a new session. > > > > > On Fri, Mar 13, 2009 at 3:24 PM, Brendan Erwin <[email protected] > > > > > wrote: > > > > I've got a strange situation, which I'm sure is outside of the > > > > normal use cases, that is giving me fits. > > > > > In order to facility some certain testing I've added an > > > > initialization mode to my application which configures NHibernate > > > > (via fluent-nhibernate's fluentlyConfigure) to use a SQLite > > > > database, generates the schema from the domain model, populates the > > > > database with some instances by creating transient models and saving > > > > them, and then uses direct (via Session.Connection) SQL to > > > > manipulate the database. > > > > > Most of that works just fine, but my problem is that once I've > > > > messed with the database via SQL directly (the direct SQL > > > > manipulation is changing the ID of some of the instances in the DB), > > > > NHibernate wont give me an instance which I know is in the database. > > > > > So, shortly: > > > > > When I manipulate an object's ID directly in the database how do I > > > > get NHibernate to work? I have destroyed and recreated my session > > > > already, do I need to recreate the SessionFactory? I'm not using the > > > > second-level cache so that answer doesn't seem right. > > > > > I'm sure I'm missing something stupid simple here... what is it? > > > > > Some of the code in question: > > > > > SQLiteUtil.SetupSqlite("INTEGRATION",true,sessionInstanceScope); > > > > SQLiteUtil.InitializeData(() => > > > > { > > > > //Create and save domain objects here... > > > > }); > > > > SQLiteUtil.InitializeData(()=> > > > > { > > > > //Fix the Model ID so that we know what it is outside > > > > SQLiteUtil.ExecuteSqlScript("UPDATE ModelTable SET > > > > ID = '14BD459F-027B-4BD3-9C31-AEA550B9808C'"); > > > > }); > > > > > The configuration code: > > > > public static void SetupSqlite(FileInfo databaseFile, bool > > > > generateSchema, InstanceScope sessionInstanceScope) > > > > { > > > > NHibernate.Cfg.Configuration cfg; > > > > > Models > > > > .Data > > > > .Util > > > > .Configuration > > > > .ConfigureDataAccess > > > > (SQLiteConfiguration.Standard.UsingFile(databaseFile.FullName), > > > > sessionInstanceScope, out cfg); > > > > > var session = ObjectFactory.GetInstance<ISession>(); > > > > session.FlushMode = FlushMode.Commit; > > > > > var connection = session.Connection; > > > > > if (!generateSchema) return; > > > > > var _dialect = Dialect.GetDialect(cfg.Properties); > > > > var drops = cfg.GenerateDropSchemaScript(_dialect); > > > > ExecuteSqlScripts(drops); > > > > > var scripts = cfg.GenerateSchemaCreationScript(_dialect); > > > > ExecuteSqlScripts(scripts); > > > > } > > > > > Initialize Data: > > > > > /// <summary> > > > > /// Sets up data in the database. Perform your domain model > > > > saves within the code block. > > > > /// </summary> > > > > public static void InitializeData(Action setupTestDataAction) > > > > { > > > > var theSession = ObjectFactory.GetInstance<ISession>(); > > > > try > > > > { > > > > theSession.BeginTransaction(); > > > > setupTestDataAction(); > > > > theSession.Transaction.Commit(); > > > > } > > > > catch (Exception ex) > > > > { > > > > if (theSession != null) > > > > theSession.Transaction.Rollback(); > > > > throw; > > > > } > > > > } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
