views:

572

answers:

2

I'm trying to present MySQL server data in a silverlight client and my current plan of attack is to use Entity Framework to MySQL with RIA Services providing the data access between the Silverlight Client and Entity Framework.

However, I'm only trying to present data to the user and I do not want the possibility of me or someone else being able to change the data in MySQL.

In short, I wish there was a way to simply ignore the setters for all entity types. I only want getters. I want "read-only" access to MySQL. However, it seems my only option is to change "Setter" on each individual field to either Internal, Private, Protected, or Public.

Is there a better way to accomplish what I'm trying to do?

+2  A: 

With the caveat that I've never used RIA services, from what I understand it's built on top of ADO.NET Data Services. There's no way (as far as I know) to stop the creation of property setters in the Silverlight generated proxy, but you can lock down the data service itself with a bit of code in its static InitializeService() method:

public class MyDataService : DataService<MyEntityModel>
{
    public static void InitializeService(IDataServiceConfiguration config)
    {
        // make all entity sets read-only:
        config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);

        // make the (example) CommentEntitySet read/writeable:
        config.SetEntitySetAccessRule("CommentEntitySet", EntitySetRights.All);
    }
}

With this method, the data service will disallow changes to any entity set except CommentEntitySet (which I included to illustrate the way in which you can can override the access rule to individual entity sets after the first line, which sets the default access rule for all entity sets to AllRead).

Ben M
So you would lock it down in the middle tier (RIA Services, ADO.NET Data Services) rather than in the model itself?
Ben McCormack
That's right--and that way, you're guaranteed nobody (not even a hacker bypassing your Silverlight application) can push changes to the model through the data service.
Ben M
It's so hard to choose just one answer! Your's is very helpful as well. Much thanks! (Also, I thought it very ironic that another "Ben M" was the first to answer my question :-).
Ben McCormack
Glad to help .. tehp's answer is more applicable to RIA services anyway. `:-)`
Ben M
+5  A: 
thepaulpage