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
-~----------~----~----~----~------~----~------~--~---

Reply via email to