客户端上仅继承 EF 代码
(抱歉我的英语不好)
在 Silverlight 4 + RIA Services + EF4 Code Only 应用程序中,我的 DbContext 上有一些包含“IsActive”字段的类 - 我想从客户端了解实体是否具有此字段并获取它。我的第一个想法是使用接口:
public interface IHasActiveField
{
bool IsActive {get; set;}
}
public class Data: IHasActiveField
{
public bool IsActive {get; set;}
}
这在服务器上工作正常,但在客户端上,RIA 生成的代码没有对我的接口的任何引用,因此我无法测试 if (obj is IHasActiveField)
- 如果我尝试从带有 IsActive
字段的基类继承,也会发生同样的情况,在客户端,类 Data
始终从 Entity
继承> - 我可能可以使用反射来查看该字段是否存在或只是测试每种类型(if (obj is Data)
),但如果可以采用更优雅的方式,那就更好了:)
(sorry for my bad english)
In a Silverlight 4 + RIA Services + EF4 Code Only application I have some classes on my DbContext that contain a "IsActive" field - I want to know from the client if a entity have this field and get it. My first thought was to use a interface:
public interface IHasActiveField
{
bool IsActive {get; set;}
}
public class Data: IHasActiveField
{
public bool IsActive {get; set;}
}
This work fine on the server but on the client, the RIA generated code do not have any reference to my interface, so I cannot test if (obj is IHasActiveField)
- the same happens if I try to inherit from a base class with the IsActive
field, on the client side, the class Data
always inherit from Entity
- I probably could use reflection to see if the field exists or just test for every type (if (obj is Data)
) but if a more elegant way is possible, it would be way better :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下博客听起来正是您想要的。
The following blog sounds like what you want.