Hi,
I am trying to use a List<t> in my application. This list contains serveral items of the entity type "Component".
I created an entity called Configuratie which has a EntitySet of type "Component". The user can created multiple "Components" before I save the "Configuration" item. To do this I at the Components to the List<t> and when I save the "Configuratie" item I loop through the List<t>.
But everytime I try to do this I get an error message
A first chance exception of type 'System.InvalidOperationException' occurred in Xtensive.Storage.dll
System.InvalidOperationException: Unable to process operation without a transaction. Use Transaction.Open(...) to open it.
at Xtensive.Storage.Session.OpenTransaction(IsolationLevel isolationLevel, Boolean autoTransaction)
at Xtensive.Storage.Session.OpenTransaction(Boolean autoTransaction)
at Xtensive.Storage.Transaction.Open(Session session, Boolean autoTransaction)
at Xtensive.Storage.Aspects.TransactionalAspect.OnEntry(Object instance)
at Xtensive.Storage.Persistent.GetFieldValueT
at Xtensive.Storage.Internals.AssociationActionProvider.<.cctor>b__0(AssociationInfo association, IEntity owner)
at Xtensive.Storage.PairIntegrity.SyncManager.Enlist(OperationType type, Entity owner, Entity target, AssociationInfo association)
at Xtensive.Storage.EntitySetBase.Add(Entity item)
at Xtensive.Storage.EntitySet1.Add(TItem item)
at fiod.drs.client.NieuwConfiguratie.<>c__DisplayClass8.<Save>b__6(Component com) in D:\Projecten\Registratie\drs.client\Editors\NieuwConfiguratie.cs:line 123
at System.Collections.Generic.List
1.ForEach(Action`1 action)
at fiod.drs.client.NieuwConfiguratie.Save(String ibncode, String merk, String soort, String serienr, String opmerking, String type) in D:\Projecten\Registratie\drs.client\Editors\NieuwConfiguratie.cs:line 123The thread 0xf44 has exited with code 0 (0x0).
This is part of the code I use to add a "Component" item to a "Configuratie" items
using (var transactionScope = Transaction.Open())
{
var configuratie = new Configuratie()
{
Object = Query<drs.model.Object>.SingleOrDefault(objectKey),
Gegevens = new ExtraInfo()
{
Ibncode = ibncode,
Merk = merk,
Soort = soort,
Serienummer = serienr,
Opmerking = opmerking,
},
Soort = (ConfiguratieTypes)configType
};
this.Schijven.ForEach(com => configuratie.Schijven.Add(com));
transactionScope.Complete();
}
Hopefully someone can help me with this problem.
Kind regards
Martijn
Updated at 26.08.2009 11:37:08
Tnx for the reply. I added a SessionConfigration to my code, see below
var config = new SessionConfiguration() { Options = SessionOptions.AutoTransactions};
Change my
Session.Open(Program.Domain)
to
Session.Open(Program.Domain, config)
But still getting the same error...
So what I am doing wrong??
Btw..any samples available that implements a this kind of logic into a method og SessionBound? > Another way to achieve the same is to place all this logic into a method of SessionBound (Entity in particular). If auto transactions are enabled, its execution will be wrapped into a transaction.
Updated at 27.08.2009 10:27:19
Hi,
I checked which version of the Xtensive.Storage.dll (C:\Program Files\DataObjects.Net v4.0.5\Bin\Release\Xtensive.Storage.dll) I use below are de details about the dll
Version: 1.0.0.12358
Create date: 15-8-2009 6:21
This is the same for the Xtensive.Storage.dll located in the GAC.
Are there any newer files then this?
Kind regards,
Martijn
Updated at 28.08.2009 9:56:02
Hello,
I did some testing on my own and it see that there error comes from the fact that I use different sessions for creating the "component" and "configuration" entities
See my example code below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xtensive.Storage;
using Xtensive.Storage.Configuration;
using TestListType.Model;
namespace TestListType
{
class Program
{
static List<Component> ComponentCollection = new List<Component>();
static Domain domain;
static void Main(string[] args)
{
var config = DomainConfiguration.Load("mssql");
domain = Domain.Build(config);
Console.WriteLine("Begin test run....");
Console.WriteLine("Create component....");
AddComponent();
Console.WriteLine("Create configuration and add component....");
AddComponentToConfiguration();
Console.WriteLine("Done!!");
Console.ReadLine();
}
static void AddComponent()
{
using (Session.Open(domain))
{
using (var transactionScope = Transaction.Open())
{
Component com = new Component()
{
Name = "Test1"
};
ComponentCollection.Add(com);
transactionScope.Complete();
}
}
}
static void AddComponentToConfiguration()
{
using (Session.Open(domain))
{
using (var transactionScope = Transaction.Open())
{
Configuration config = new Configuration()
{
Name = "Config1"
};
ComponentCollection.ForEach(c => config.Components.Add(c));
transactionScope.Complete();
}
}
}
}
}
TestListType.Model
using System;
using Xtensive.Storage;
namespace TestListType.Model
{
[HierarchyRoot]
public class Component:Entity
{
[Field, Key]
public int Id { get; private set; }
[Field]
[Association(PairTo = "Components", OnOwnerRemove = OnRemoveAction.Clear)]
public Configuration Configuration { get; set; }
[Field]
public string Name { get; set; }
}
[HierarchyRoot]
public class Configuration : Entity
{
[Field, Key]
public int Id { get; private set; }
[Field]
public string Name { get; set; }
[Field]
public EntitySet<Component> Components { get; private set; }
}
}
If you use the same session for both functions it works fine.
So my question is...how can I, in my case use the same session while using different button_click events to create a "Configuration" item.
Kind regards,
Martijn.
This thread was imported from our support forum. The original discussion may contain more detailed answer.