Discovering Entities...Only Once...EVER? - SOLVED

Sep 29, 2013 at 7:13 AM
I'm trying to get my implementation up and running. I cannot wait for this to be working! Thanks for all the efforts on this library. I know it is saving me a ton of time I didn't have.

Now on to my issue:
When I start up my application in the constructor of my main form, I have the following code:
            _dbStore = new SQLiteDataStore(Path.Combine(m_strHistoryPath, "history.db"));
            if (!_dbStore.StoreExists)
            {
                _dbStore.CreateStore();
            }
            _dbStore.DiscoverTypes(System.Reflection.Assembly.Load("HistoricalData"));
This works fine the first time through. However, any consecutive time through it throws an Error in the DataStore file on line 365 claiming that one of my entities already exists, but it uses the actual database name that I used instead of the class name.

When I move the code into this structure:
            _dbStore = new SQLiteDataStore(Path.Combine(m_strHistoryPath, "history.db"));
            if (!_dbStore.StoreExists)
            {
                _dbStore.CreateStore();
                _dbStore.DiscoverTypes(System.Reflection.Assembly.Load("HistoricalData"));
            }
I make it further. I am having an issue beyond this point... but I don't know how to describe it. It simply lets me know that there is a NullReferenceException, but has no code or symbols to load. I assumed it didn't have any Entities so I reverted the second code to the first hoping I had fixed the over discovery issue by some accident.

I need help getting this to create the tables and also to save data. I have to be 100% sure all of the data is being recorded before I can deploy this to a customer. I'm sure you understand.

I'm sure I could easily be doing something wrong, but I'm simply trying to piece together the documentation, samples, and forum posts into the solution I need. Please forgive any noob oversights.

Thanks!
Jarvis
Sep 29, 2013 at 7:44 AM
Well I know now that I do need to discover the entities. I was just looking at my Call Stack... I notice it's actually attempting to add the same one twice, and it seems it may be thinking it needs to do that due to adding an entity further down the chain first? I'm not sure what's causing this issue yet. I'm trying to walk through it, but it's a slow debug process going through all the ORM code.

Any pointers or help would be greatly appreciated.

Thanks!
Jarvis
Sep 29, 2013 at 7:47 AM
It is definitely attempting to load one of my classes twice. This class is derived from another Entity class. This particular class I wasn't actually going to use as an Entity as it simply provided some functionality no properties to store. Now I have added an ID field and made it an entity. It's still attempting to get loaded. Would it make more sense to manually load the specific Entities I know I have created?

I would more prefer it to be dynamic so I can add as I go without having to update a specific other portion of code to get it working. That's just my preference.

Thanks,
Jarvis
Sep 29, 2013 at 7:51 AM
Another interesting note... The class it's loading twice that didn't have an EntityAttribute on it until after I started debugging this error is not the entity name it's displaying as a duplicate.

I have a class TextFeature : BaseFeature, ITextFeature < NameInStore = "text_feature_history"
I have a class BaseFeature < NameInStore = "feature_history"

I'm seeing in the Call Stack the loading of TextFeature twice. I have setup a break point on line: 333 in the DataStore.cs file this also confirmed the double loading of TextFeature for some reason. Yet when it complains of an entity already existing it says that "feature_history" already exists. That would be BaseFeature. I don't know why it would think it's needing to re-create that entity.

Thoughts?

Thanks!
Jarvis
Sep 29, 2013 at 8:07 AM
I'm getting the feeling this is having something to do with my class TextFeature inheriting from BaseFeature. Is that possibly correct?

If so, what can I do about it? I posted in another thread that I marked Solved about how I was going to handle inherited classes... Class Table Inheritance

Thanks,
Jarvis
Oct 4, 2013 at 3:45 AM
I solved this issue simply by manually adding my own types and not allowing it to Dynamically add them.

I however didn't get any cascaded data saved into the database. :(
Coordinator
Oct 10, 2013 at 12:30 AM
This still smells like a bug in ORM. I'll try to repro it.