Entity Framework result set not correct

This is a common problem that most of the people run into. You create an entity model to your view or table. Create a domain service and the client side code. In the client side code you put the filter and you run expecting to get some data but you end up getting one or few rows. I ran into the same problem yesterday. When I ran the program I got just the first row of the expected result.

The problem in my case, when I created the model from my table, I made some changes to attributes, removed bunch of columns, while doing it, i removed the unique key that identified the rows. It seems that if Entity Framework can not uniquely identify the rows, it does not return all the rows. To fix it, all I had to do is, go back to the model, make the fields that uniquely identify the rows, recompile and that’s it.

So if you run into any situation where the rows are not coming properly, this may be one of the culprit.

Technorati Tags: ,


WebContext and how to make sure client code gets it

When you create RIA services, you want to make sure the ‘WebContext’ is available for the clients to consume the services. WebContext is created by Visual studio from the web project you are pointing to in WCF RIA link. Here are the couple of things you need to do to make sure you are not going run into ‘WebContext’ not found compilation error.

1. First and foremost, check the client side project property and make sure under ‘Silverlight’ tab, the last option ‘WCF RIA Services link’ is pointing to the correct web service project.

2. Enable ‘Show All Files under Solution explorer and find the ‘Generated_Code’ folder and remove everything from there.

3. Restart VS2010 (some times it works too, at least when I was testing with Beta, on some occasions, restarting VS IDE resolve the problem.)

Technorati Tags: ,,,

How to preserve the user information in service context

This is follow up to my previous blog on things to watch out when developing application using SL3 + RIA. One issue I ran into during the testing is that the user information did not get persisted as I would have thought. One of the implementation suggested that, Use create the Authentication Service and then implement a singleton pattern to preserve the user once the validation user is successful. From there all the services can consume the singleton user. In my development everything worked great. I didn’t even think twice because each service request will run in its own application domain and so singleton will be a good solution. Well it turned out that my ‘assumption’ was wrong. It seems when two people access the same silver light page, the first user information gets the store and all following users end up using the first user identity and of course it is wrong.

To resolve that problem, I ended up removing the singleton user and started access the User information directly off of ServiceContext.User, but here is the catch. If you override the User information with your custom user and added some property to it, it is not available. But for starters, I have resolved the current problem and I will revisit to see why I can not user custom user I have created.

SL3 + RIA custom authentication

I have been playing with Custom Authentication lately and while trying out, I ran into bunch of problem. So I thought I will point out few of things you need to watch out. When you create a SL3 + RIA services, it automatically gives you Windows Authentication. When you need to change to custom authentication, couple of things you need to change and for that I would recommend Brad Abrams (ex-Microsoft) blog

If you are new to this area I would strongly recommend you to look at the authentication quick starts in the following URL, they are very simple and easy to follow.


while you are at it, I would recommend visiting this Silverlight forum question to have an understanding of authentication as well.

Few things to watch out are

1. Make sure you have <authentication mode="Forms" /> in your web.config at the WCF service side.

2. The USER return from GetAuthenticatedUser has a catch, if you do not assign the name to the returning user, then by default IsAuthenticated flag will be false.

3. Make sure you have authentication setup to form authentication in silver light app.xaml.


4. If you have a page where you are authenticating and then data binding, do not do data binding till you complete the validation. In other words, make sure you add the root visual element on login completed method delegate.

If you run into any other problems let me know or if you have any comments or suggestion also send me a mail.