With the Random.generate example in chapter 3, is it possible to execute the resulting Cmd in elm-repl?

The concept of Commands is new to me and you explained them well in chapter 3. However, it would be nice be able to actually generate the random numbers in the shell, using similar code (without resorting to seeds), using a union type like Msg.


> type Msg = Nothing | SelectByIndex Int
> import Random
>
> cmd = Random.generate SelectByIndex (Random.int 0 2)

Can I somehow execute the 'cmd' manually in the shell?
I personally don't like Vb.net. However, from time to time, I've had to code in it over the years, for different reasons. Therefore, it would be nice to have as a reference, but I would be happy with it as a separate download, assuming it's easy to match up the examples in the book.
This is not specific to EF, however, I couldn't find the answer googling it.

How can you confirm in sql profiler the isolation level that you set in code? The 'Audit Login' always says 'set transaction isolation level read committed', even when I set the transction options to 'Serializable'.

The tool 'Entity Framework Profiler' display of the isolation level refects what's set in code, but the sql profiler does not.

Does anyone know why?
Thanks.
John
In plain ado.net, when I do create two successive connections with serializable isolation level, the 'Audit Login' for the first connection says 'set transaction isolation level read committed', while the 2nd connection's 'Audit Login' says 'set transaction isolation level serializable'.

Again, I know this is not directly related to the book. However, I'm sure the answer would help out other developers that use this book. And if you are using any ORM, youÂ’re going to be looking at sql profiler a lot.
Stefano, thanks for the reply.

This is how I understand things; please correct what I have wrong:

- every call to SaveChanges is it's own transaction that begins and ends

- if you need to do queries and database saves and have all of it to be in the same transaction, you need to use TransactionScope

- when I wrote a query like described here, http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2007/08/27/9665.aspx, doing a query and saves against the same database within one transaction, the error messages that results indicated that it was using MSDTC.

John
Hi. All in all I think your book is very helpful. But, you should go into more detail about transactions.

For example, with ADO.net (and with NHibernate) you can easily work with transactions and set the Isolation level using the IDbTransaction.IsolationLevel. Is it true that with EntityFramework you need to use TransactionScope and TransactionScopeOptions, which is a network thing that needs to be turned on, both in the calling computer and the database computer?

In my employer's intranet, these options were turned off, MSDTC. Why can't EntityFramework allow you to work with IDbTransaction?

Thanks for any help.
John
This thread helped me with this issue: http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/58a2458f-9404-4686-b711-5cff8fb02181

To avoid 'MSDTC escalation' I needed to call ctx.Connection.Open(); When I put that statement in the method below, the transaction saved without error.

Here is a code sample for the helper method:

public class ContextHelper
{
public delegate void ContextHandler<T>(T ctx) where T : ObjectContext;

public static void Complete<T>(ContextHandler<T> handler, MyIsolationLevel isolationLevel = MyIsolationLevel.Serializable) where T: ObjectContext, new()
{
using (var ctx = new T())
{
var options = new TransactionOptions();
options.IsolationLevel = isolationLevel;

using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew, options))
{
ctx.Connection.Open(); //****This statement was needed to avoid**** 'MSDTC escalation'
handler(ctx);

ctx.SaveChanges();
scope.Complete();
}
}
}

}
Since this is the first time posting for this book, let me say that I'm getting a lot out of it; it's helping me learn EF in a deeper way. Thanks.

As far as 'ApplyCurrentValues', you show an example on page 179 + 180, where the address info was being lost because the disconnected client wasn't explicitly setting those properties. And that the solution was to use ApplyCurrentValues:

ctx.Companies.OfType<Customer>().First(c => c.CompanyId ==cust.CompanyId);
ctx.Companies.ApplyCurrentValues(cust);
ctx.SaveChanges();

However, when I test this, the behavior I get is different. What happens is that the 'null' values are saved back in the database. ApplyCurrentValues seems to set all values from 'cust' including the null ones.