如何在数据服务(OData)中创建计算属性? [英] How to create a computed property in Data Services (OData)?

查看:67
本文介绍了如何在数据服务(OData)中创建计算属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用EDMX与WCF数据服务一起创建OData服务.如何为实体类型创建计算属性,以便其值在服务(C#)中进行计算而不是来自数据库?
此属性的值基于其他属性的值,这些属性映射到数据库中的字段.

I am creating an OData service with WCF Data Services using an EDMX. How can I create a computed property for an entity type, so that its value gets computed in the service (C#) and does not come from the database?
The value of this property is based on the value of other properties, which are mapped to fields in the database.

推荐答案

我发现的解决方案是使用Entity Framework Code First而不是EDMX.它允许您仅通过在代码中创建标准属性来创建计算属性.
这是一个示例:

The solution I found is to use Entity Framework Code First instead of an EDMX. It allows you to create computed properties just by creating standard properties in code.
Here is an example:

public class Person
{
  public String FirstName { get; set; }
  public String LastName { get; set; }
  public String FullName
  {
    get { return FirstName + " " + LastName; }
  }
}

这篇关于如何在数据服务(OData)中创建计算属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆