无法找到属性:在entityType上的Nome:

时间:2013-07-08 14:47:23

标签: asp.net-web-api odata breeze

问题

  

无法找到属性:Nome on entityType:Modalidade:#CreditoImobiliarioBB.Model

但是这个属性在课堂上! 未生成/odata/modalidades请求,仅请求/odata/$metadata

代码

域类

public class Modalidade : INamedEntity
{
    public int Id { get; set; }

    [StringLength(80), Required]
    public string Nome { get; set; }
}

配置

public static class WebApiConfig 
{
    public static void Register(HttpConfiguration config)
    {
        var modelBuilder = new ODataConventionModelBuilder(config);
        modelBuilder.EntitySet<Modalidade>("modalidades");
        modelBuilder.Namespace = "CreditoImobiliarioBB.Model";
        config.Routes.MapODataRoute(routeName: "odata", routePrefix: "odata", model: modelBuilder.GetEdmModel());

        var jsonFormatter = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
        var enumConverter = new StringEnumConverter();
        jsonFormatter.SerializerSettings.Converters.Add(enumConverter);
        var jqueryFormatter = config.Formatters.FirstOrDefault(x => x.GetType() == typeof(JQueryMvcFormUrlEncodedFormatter));
        config.Formatters.Remove(config.Formatters.XmlFormatter);
        config.Formatters.Remove(config.Formatters.FormUrlEncodedFormatter);
        config.Formatters.Remove(jqueryFormatter);

        config.Formatters.JsonFormatter.SerializerSettings.DateFormatHandling = DateFormatHandling.IsoDateFormat;
    }
}

public static class BreezeWebApiConfig
{
    public static void RegisterBreezePreStart()
    {
        GlobalConfiguration.Configuration.Routes.MapHttpRoute(
            name: "BreezeApi"
            , routeTemplate: "api/{controller}/{action}"
            , defaults: new { action = "Get" }
        );
    }
}

CoffeScript

微风的默认值

breeze.NamingConvention.camelCase.setAsDefault()
breeze.config.initializeAdapterInstances
    dataService: "OData"

查询

query = new breeze.EntityQuery().from("modalidades")
query = query.where("Nome", breeze.FilterQueryOp.Contains, @TermoBusca()) if @TermoBusca()
query.orderBy("Nome")

manager = new breeze.EntityManager("/odata/")           
promise = manager.executeQuery(query)
    .finally ->
        notice.pnotify_remove()
        filterUrl = creditoimobiliario.getParameterByName "\\$filter", @url
        _this.TermoBusca "$filter=#{filterUrl}" if filterUrl
    .fail creditoimobiliario.displayXhrNotifyError
promise.then (data, status, xhr) =>
    return if not status or status != 200
    ko.utils.arrayPushAll @Collection, data.value
    @NextUrl data["odata.nextLink"]
promise

元数据

<EntityType Name="Modalidade">
    <Key>
        <PropertyRef Name="Id" />
    </Key>
    <Property Name="Id" Type="Edm.Int32" Nullable="false" />
    <Property Name="Nome" Type="Edm.String" Nullable="false" />
</EntityType>

2 个答案:

答案 0 :(得分:3)

我在this link找到了答案。

解决方案只是注释代码<{1}}的这一行

答案 1 :(得分:0)

不确定确切的问题,但Microsoft的 ODataConventionModelBuilder 的当前状态是它不支持完整的OData规范。特别是它还不支持外键的定义(Breeze需要)。它也可能存在其他问题。微软声称这将在以后的版本中修复。

目前我只是使用Microsoft的WCF数据服务向EFata公开EF模型。类似的东西:

public class ODataService : DataService<MyEFContext> {

    // This method is called only once to initialize service-wide policies.
    public static void InitializeService(DataServiceConfiguration config) {
      // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
      // Examples:
      // config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.All);
      ...

       config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
       config.UseVerboseErrors = true;
}