简体   繁体   English

如何创建一个从实体对象继承的类??? (实体框架)

[英]How to create a class that inherits from an entity object??? (Entity Framework)

I have a Silverlight Bussiness Application, I'm using Entity Framework Data model, and I have an entity class called Clients, with some properties: Name, LastName, Address, etc. I need to create a class that inherits from Clients class, I need something like this... 我有一个Silverlight Bussiness应用程序,正在使用Entity Framework Data模型,并且有一个名为Clients的实体类,它具有一些属性:Name,LastName,Address等。我需要创建一个从Clients类继承的类,需要这样的东西...

public class ClientWithSubClients : Clients
{
    public bool HasSubClients { get; set; }
    public List<Clients> SubClients { get; set; }
}

I need it to have in the same class, the information of the Client, and the information of the SubClients... On server side works fine, but I need to use it on client side, and in the silverlight project I can't see the class definition... any idea... 我需要它具有相同的类,客户端的信息和子客户端的信息...在服务器端工作正常,但是我需要在客户端使用它,而在Silverlight项目中,我不能看到类定义...任何想法...

Thanks... Miguel 谢谢... Miguel

You won't be able to see the entity framework types directly in Silverlight, because EF relies on the full .net framework, and is in your case a server-only technology. 您将无法直接在Silverlight中查看实体框架类型,因为EF依赖于完整的.net框架,并且在您的情况下,它是仅用于服务器的技术。

To expose the EF types to a Silverlight client, you need some sort of server side service as a wrapper. 要将EF类型公开给Silverlight客户端,您需要某种服务器端服务作为包装器。 I've used WCF data services (http://msdn.microsoft.com/en-us/data/odata.aspx) for this exact requirement and it works quite nicely. 我已经使用WCF数据服务(http://msdn.microsoft.com/zh-cn/data/odata.aspx)来满足此确切要求,并且效果很好。 WCF RIA services (http://www.silverlight.net/learn/advanced-techniques/wcf-ria-services/get-started-with-wcf-ria-services) is another alternative as well. WCF RIA服务(http://www.silverlight.net/learn/advanced-techniques/wcf-ria-services/get-started-with-wcf-ria-services)也是另一种选择。

I think if you are only ever going have Silverlight clients consuming your data, WCF RIA services is the best choice. 我认为,如果仅让Silverlight客户端使用您的数据,则WCF RIA服务是最佳选择。 If you want a more broadly accessible service, use WCF Data Services. 如果您想要更广泛地访问服务,请使用WCF数据服务。

We use WCF data services, because we have silverlight apps, WPF apps, and even Excel spreadsheets consuming the services. 我们使用WCF数据服务,因为我们有Silverlight应用程序,WPF应用程序甚至使用该服务的Excel电子表格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM