“只读”实体框架?我正在尝试使用 RIA 服务、EF 和 Silverlight

发布于 2024-08-05 22:42:46 字数 366 浏览 0 评论 0原文

我正在尝试在 silverlight 客户端中呈现 MySQL 服务器数据,我当前的攻击计划是使用实体框架到 MySQL,并通过 RIA 服务提供 Silverlight 客户端和实体框架之间的数据访问。

然而,我只是想向用户呈现数据,我不希望我或其他人能够更改 MySQL 中的数据。

简而言之,我希望有一种方法可以简单地忽略所有实体类型的设置器。我只想要吸气剂。我想要对 MySQL 进行“只读”访问。但是,我唯一的选择似乎是将每个单独字段上的“Setter”更改为内部私人受保护公开。

有没有更好的方法来完成我想做的事情?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小帐篷 2024-08-12 22:42:46

如果您正在使用 RIA 服务...

当您创建域服务类(这本质上就是 RIA)时,它将弹出一个对话框,您可以在其中单击“启用编辑”。在您的情况下,只需不要单击它,就不会生成任何编辑功能。

RIA Services 用于连接服务器和客户端,它只是不生成 CRUD 的 CUD 部分

< img src="https://i.sstatic.net/mTE46.png" alt="来自某个博客">
(来源:silverlightshow.net

If you're using RIA Services...

When you create a Domain Service Class (which is in essence what RIA is), it will bring up a dialog that you can click "enable editing" on. In your case, just don't click it and none of the editing functionality will be generated.

RIA Services is for connecting the server and the client, and it can just Not generate the CUD part of teh CRUD

from some blog
(source: silverlightshow.net)

俏︾媚 2024-08-12 22:42:46

需要注意的是,我从未使用过 RIA 服务,据我了解,它是构建在 ADO.NET 数据服务之上的。没有办法(据我所知)停止在 Silverlight 生成的代理中创建属性设置器,但是您可以使用其静态 InitializeService() 中的一些代码来锁定数据服务本身方法:

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);
    }
}

使用此方法,数据服务将不允许对除 CommentEntitySet 之外的任何实体集进行更改(我将其包括在内是为了说明如何在第一行之后覆盖对各个实体集的访问规则) ,它将所有实体集的默认访问规则设置为AllRead)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文