LINQ select nullable Id

2013-03-03 Thread Greg Keogh
Folks, I want to select the int Id of an entity in a DbSet, or int? null if it's not found. Like this *wrong* sample: int? id = (from t in things where t.Name == "Foo" select t.Id).FirstOrDefault(); In this case I get int zero if there is no match but I want null. Is there some way of rearranging

Custom Attribute

2013-03-03 Thread Stephen Price
Hey all, I've written a custom attribute that duplicates the behaviour of PrincipalPermissionAttribute (It checks the user roles against my own Authentication service instead of looking at the Thread.CurrentPrincipal) I've noticed that it works but only seems to check the first time you access th

Re: Async coding pattern

2013-03-03 Thread Greg Keogh
Thanks everyone for your comments, and Dave for pointing out the Bcl.Async package. I am running with the sample James C-S gave. I found the same coding pattern somewhere in a search and I find it acceptable for now. I'll let you know if there are any stunning revelations on this issue. Greg K

RE: Async coding pattern

2013-03-03 Thread James Chapman-Smith
Try this Greg: EventHandler handler = null; handler = (s, e) => { client.GetFooCompleted -= handler; Trace("GetFoo result is {0}", e.Result); }; client.GetFooCompleted += handler; client.GetFooAsync(rowId); You'll have to put i

RE: Async coding pattern

2013-03-03 Thread David Kean
Not sure I follow. There are three typical ways we do "async" in the framework: 1) Event based async 2) BeginXXX, EndXXX 3) Task The compiler await/async implicitly works with 3). You can also make it work 2) with TaskFactory.FromAsync. Included as part of our package below (

Re: Async coding pattern

2013-03-03 Thread Davy Jones
Async/await. = begininvoke endinvoke Tasks = backgroundwork / threadpool Events are still events you can't replace them with the new 4.0 threading. Davy Sent from my starfleet datapad. On 3 mars 2013, at 05:18, David Kean wrote: Why still using event based async, when you can use async/awai