I have been breaking my head over this for the last couple of hours and I'm unable to identify what exactly I'm doing wrong. It's probably very simple. I tried to mimic the 4.3 WPF sample as this covers most of what I need to be able to do. Since I am developing a WPF application I resort to using the disconnected state approach. (I migrated from DO 4.3 to DO 4.4.) (Also, I don't know if it's vital, but I plan to use 2 different domains simultaneously.) I created an Entity called GlobalSettings which contains 2 fields, namely Id (int) and Data (string). When the application starts I initialize my service which creates a new Domain using an SQL CE database file. (Also note that my database should contain only 1 instance of a GlobalSettings object)
When I start the application the first time my database file is created, Get() returns an empty string as expected, I fill it in with default data and continue my application run. When the application is closing the Set() function is called and does not report any errors. So it looks like everything went OK. However, when I start my application a second time I expect to be able to read out the previously stored data. But when I enter the Get() function and the Query.All<t>() call is performed it doesn't return any objects so it returns an empty string again. I see no exceptions or errors, hence I assume everything went OK. What am I doing wrong here? |
I am adding another answer since I don t have enough space to type everything in the comment box. It is pretty much all the code, the only missing part is the domain creation. This function is only called once by the constructor of my service.
I was unable to attach the SQL profiler. The links that point out how are no longer available. I did found something in Google cache, but I am creating a standalone library. My main .exe has nothing to do with DataObjects, so when I tried to add several things to the app.config file it would throw some exceptions. Is there a way to configure this from within the code? I modified the code according to your suggestions. So, in the constructor of my service I create the Domain and call the Reset() function. I changed the Get() and Set() functions of my service to the following:
I create my domain using the Default profile. When the database file is created it is 148kb in size, but normally after adding the settings it does not grow in size, and I would expect that to happen significantly. I do find it strange that I need to call Reset() after doing the Set(). But that's the way things are done in the WPF example that is part of DO4.3. Also, you say I should minimize the transaction scope. I don't think I can do that for most things in my application. Since I am creating a WPF (MVVM) application I need to have a start (where I init) and I need to be able to do hundreds of operations over a few hours and only at the end my user has the option to save or not. When looking at other ORM frameworks this is much easier as they don't store changes on objects until I explicitly call Save() or something alike. (Given, within a transaction scope, but it's done on the object itself rather than on the total system state.) Oh, I also tried without using the disconnected state object and since Get() and Set() should only be called once in the entire application, I first approached them apart from each other. Each created the domain, the session and did everything on their own, but when I called the Set() I got an error that I needed to open a Session() first, but that was clearly done. So that's why I started using the disconnected state. edit: I got the logging working. As far as I can see it correctly detects that my schema did not change and thus it doesn't perform any upgrades. In my Get() function it logs the following data:
Whether or not I start from a clean DB file, it always throws the same exception. In my Set() function it logs the following:
|