so, I like Linq2Sql behavior very much and it looks really convinient to me. See the difference with between clientprofile and linq2sq
1 linq2sql:
using (var ts = new TransactionScope())
{
using (var db = new DataClasses1DataContext())
{
var e = new MyEntity() { Id = 123, Text = "qweqweqweqwe" };
db.MyEntities.InsertOnSubmit(e);
db.SubmitChanges();
Assert.That(db.MyEntities.Count(), Is.EqualTo(1)); // TADA! This passes
}
ts.Complete();
}
2: DO4.4
var config = DomainConfiguration.Load("Default");
var domain = Domain.Build(config);
var scfg = new SessionConfiguration()
{
Options = SessionOptions.ClientProfile
};
using (var session = domain.OpenSession(scfg))
{
using (var transactionScope = session.OpenTransaction())
{
// Creating new persistent object
var helloWorld = new MyEntity(session)
{
Text = "Hello World!"
};
foreach (var myEntity in session.Query.All<MyEntity>())
{
Console.WriteLine(myEntity.Text); // no entities :(((
}
// Committing transaction
transactionScope.Complete();
}
using (var transactionScope = session.OpenTransaction())
{
foreach (var myEntity in session.Query.All<MyEntity>())
{
Console.WriteLine(myEntity.Text); // no entities :((( i've completed the transaction(!)
}
transactionScope.Complete();
}
session.SaveChanges();
}
// Reading all persisted objects from another Session
using (var session = domain.OpenSession())
{
using (var transactionScope = session.OpenTransaction())
{
foreach (var myEntity in session.Query.All<MyEntity>())
{
Console.WriteLine(myEntity.Text); // here we go...
}
transactionScope.Complete();
}
}
And this is really frustrating, that I cant access my newly created entity via standard methods.
asked
Mar 16 '11 at 10:30
xumix
425●75●76●82