0

问题

无法找到属性: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" }
        );
    }
}

咖啡脚本

微风的默认值

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>
4

2 回答 2

3

我在这个链接中找到了答案。

解决方案是简单地注释这行NamingConvention.camelCase.setAsDefault();代码

于 2013-07-09T02:25:53.283 回答
0

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

现在,我将简单地使用 Microsoft 的 WCF 数据服务将 EF 模型公开给 OData。就像是:

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;
}
于 2013-07-08T19:05:28.710 回答