AspNet.Odata V4 Inject计算了getonly属性

时间:2017-10-10 05:07:18

标签: c# asp.net-web-api odata

我有一个实体人:

public class Person
{
  public string FirstName { get; set; }
  public string LastName { get; set; }
}

现在我构建模型

public static ODataModelBuilderEx CreatePersonModel(this ODataModelBuilderEx builder)
{
    builder.AddEnum<TypeCode>();
    var persons = builder.EntitySet<Person>("Persons");

    var person = persons.EntityType;
    person.Property(x => x.FirstName);
    person.Property(x => x.LastName);
    return builder;
}

是否可以公开计算属性&#39; FullName&#39;不将此属性添加到Person类?

这样的事情:

person
    .Property("FullName", x => x.FirstName + " " + x.LastName)
    .Returns<string>();

返回的json应如下所示:

{
  "FirstName" : "John",
  "LastName" : "Smith",
  "FullName" : "John Smith"
}

0 个答案:

没有答案