I just started using db4o in C #, and I had problems installing UniqueConstraint on the database ..
here is the db4o configuration
static IObjectContainer db = Db4oEmbedded.OpenFile(dbase.Configuration(), "data.db4o");
static IEmbeddedConfiguration Configuration()
{
IEmbeddedConfiguration dbConfig = Db4oEmbedded.NewConfiguration();
dbConfig.File.GenerateUUIDs = ConfigScope.Globally;
dbConfig.File.GenerateVersionNumbers = ConfigScope.Globally;
dbConfig.Common.ObjectClass(typeof(DAObs.Environment)).ObjectField("Key").Indexed(true);
dbConfig.Common.Add(new Db4objects.Db4o.Constraints.UniqueFieldValueConstraint(typeof(DAObs.Environment), "Key"));
return dbConfig;
}
and object to serialize:
class Environment
{
public string Key { get; set; }
public string Value { get; set; }
}
every time I get some values, "The reference to the object is not installed in the instance of the object." A pop-up with a stack trace pointing to UniqueFieldValueConstraint is excluded. In addition, when I comment on two lines after the comment “Initialize indexes”, everything works fine (except for saving unique keys, which is a problem) ~
Commit Code (In case I do something wrong in this part too :)
public static void Create(string key, string value)
{
try
{
db.Store(new DAObs.Environment() { Key = key, Value = value });
db.Commit();
}
catch (Db4objects.Db4o.Events.EventException ex)
{
System.Console.WriteLine
(DateTime.Now + " :: Environment.Create\n" + ex.InnerException.Message +"\n" + ex.InnerException.StackTrace);
db.Rollback();
}
}
Help me please? Thanks in advance ~
source
share