"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!
It seems as if you're trying to use Nbernate to import your data (or create an entity if it doesn't exist) which doesn't seem correct.
You are correct, I'm trying to use Nbernate to import my data. Basically, I have a system that has some authors (and books) already in it. I get a feed of data that has more authors (and books) in it.
I want to take that feed and import the books/authors into my system that I don't already have. There's a lot more going on in the import as well, which is why I'm translating to the domain model and using Nbernate to import (instead of just keeping it in a dataset and using ADO to import the data. Is this possible?
– Jamie Apr 29 '10 at 21:06 I'm guessing it is possible, but I'm not sure how to do it. My advice is to use a different tool to do the import. – Lester Apr 30 '10 at 11:49.
Most database implementations support a conditional UPDATE-or-INSERT syntax. Oracle, for example, has a MERGE command. In combination with a bernate block in your mapping you should be able to work something out.
I don't know Fluent but I assume it supports this too.
Just realize I never gave an answer or approved another's answer. I ended up just writing a new SaveOrUpdate which takes a parameter to check for existing before persisting. I also added an attribute to my domain models to overwrite when saving/updating (although in retrospect it's only on updating that it'd be overwriting).
Here's the code if it can help anyone else in this dilemma: public TEntity SaveOrUpdate(TEntity entity, bool checkForExistingEntity) { IRepository repository = new Repository(); if (checkForExistingEntity) { if (entity is Entity) { IEnumerable props = (entity as Entity). GetSignatureProperties(); Dictionary parameters = props. ToDictionary(propertyInfo => propertyInfo.Name, propertyInfo => propertyInfo.
GetValue(entity, null)); TEntity duplicateEntity = repository. FindOne(parameters); if (duplicateEntity! = null) { // Update any properties with the OverwriteOnSaveUpdate attribute foreach (var property in RepositoryHelper.
GetUpdatableProperties(typeof(TEntity))) { object initialValue = property. GetValue(entity, null); property. SetValue(duplicateEntity, initialValue, null); } // Fill in any blank properties on db version foreach (var property in typeof(TEntity).GetProperties()) { if (property.
GetValue(duplicateEntity, null) == null) { object initialValue = property. GetValue(entity, null); property. SetValue(duplicateEntity, initialValue, null); } } return duplicateEntity; } } } return SaveOrUpdate(entity); }.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.