问题
无法找到属性: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>