Breeze 微风控制器未返回正确响应
我有一个简单的模型,首先是Entity Framework 5代码,ActiveEntity是一个抽象类,具有int-Id属性和bool-IsActive字段Breeze 微风控制器未返回正确响应,breeze,Breeze,我有一个简单的模型,首先是Entity Framework 5代码,ActiveEntity是一个抽象类,具有int-Id属性和bool-IsActive字段 public class License:ActiveEntity { public string LicenseName { get; set; } public LicenseType LicenseType { get; set; } public State State { get; set; }
public class License:ActiveEntity
{
public string LicenseName { get; set; }
public LicenseType LicenseType { get; set; }
public State State { get; set; }
public DateTime DateIssued { get; set; }
public int ValidFor { get; set; }
}
public class LicenseType:ActiveEntity
{
[StringLength(100),Required]
public string Description { get; set; }
}
public class State:ActiveEntity
{
[StringLength(2)]
[Required]
public string Name { get; set; }
[Display(Name = "Long Name")]
[Required, StringLength(25)]
public string LongName { get; set; }
}
Breeze在LicenseController上调用GetLicenses:
[BreezeController]
public class LicenseController : ApiController
{
private readonly EFContextProvider<LicensingContext> db = new EFContextProvider<LicensingContext>();
[HttpGet]
public string Metadata()
{
return db.Metadata();
}
[HttpPost]
public SaveResult SaveChanges(JObject saveBundle)
{
return db.SaveChanges(saveBundle);
}
[HttpGet]
public IQueryable<License> GetLicenses()
{
//for debugging purposes
var retVal = db.Context.Licenses
.Include(l => l.State)
.Include(l=>l.LicenseType);
return retVal;
}
}
}))
如果您想知道为什么会发生这种情况,并且仅针对前三项,我们将不胜感激。我喜欢微风作为我们需要写的一些水疗的潜力,但这引起了我的一些担忧
更新1
如果我在其工作的数据库中更改LicenseType_id的顺序,则初始顺序为123123
如果更改为312123或321123,则响应中的所有六个都是正确的
[{“$id”:“1”,“$type”:“Volt.Telecom.Licensing.Models.License,Volt.Telecom.Licensing.Models”,“LicenseName”:“低压”,“LicenseType”:“{“$id”:“2”,“$type”:“Volt.Telecom.Licensing.Models.LicenseType,Volt.Telecom.Licensing.Models”,“Description”:“总承包商”,“IsActive”:false,“id”:3},“州”:“{“$id”:“3”,“$type”:”“Volt.Telecom.Licensing.Models.State,Volt.Telecom.Licensing.Models”,“Name”:“FL”,“LongName”:“Florida”,“IsActive”:false,“Id”:23}”,发布日期:“2012-11-18T00:00:00.000”,“ValidFor”:1095,“IsActive”:false,“Id”:1},{“$Id”:“4”,“$type”:“Volt.Telecom.Licensing.Models.licension,Volt.Telecom.Licensing.Models”,“licensed.Models”,“licensed”:“承包商”,“licensedtype”:“{$Id”:“5”:“,”$type:“Volt.Telecom.Licensing.Models.LicenseType,Volt.Telecom.Licensing.Models”,“Description:“Low Voltage”,“IsActive”:false,“Id”:1},“State:{“$ref:”3“}”,DateIssued:”2012-11-18T00:00:00:00.000”,“ValidFor”:1095,“IsActive”:false,“Id”:2},{“$Id:”6“,”type:”Volt.Telecom.Licensing.Models,Volt.Licensing.Licensing.Models,Volt.Licensing.Models”,“License:”licenses:“licenses“总承包商”、“被许可人类型”:{“$id”:“7”,“$type”:“Volt.Telecom.Licensing.Models.LicenseType,Volt.Telecom.Licensing.Models”,“Description”:“承包商”、“IsActive”:false,“id”:2},“State”:{“$ref”:“3”},“DateIssued”:“2012-11-18T00:00:00.000”,“ValidFor”:1095,“IsActive”:false,“id”:3},{$id:“8”,“$type”:”Volt.Telecom.Licensing.Models.License,Volt.Telecom.Licensing.Models,LicenseName:“低压”,“LicenseType:”{“$ref:”5“},“州:”{“$id:”9“,“$type:”Volt.Telecom.Licensing.Models.State,Volt.Telecom.Licensing.Models”,“名称:”:“CA”,“LongName:”加利福尼亚”,“IsActive:”假,“id:”35},“发布日期:““2012-11-18T00:00:00.000”,“ValidFor:”1095,“IsActive”“:false,“Id”:4},{“$Id”:“10”,“$type”:“Volt.Telecom.Licensing.Models.License,Volt.Telecom.Licensing.Models”,“LicenseName”:“Contractors”,“LicenseType”:{“$ref”:“7”},State:{“$ref”:“9”},DateIssued:“2012-11-18T00:00:00.000”,“ValidFor”:1095,“IsActive”:false,“Id”:5},{“$Id”:“11”,“$type”:”“Volt.Telecom.Licensing.Models.License,Volt.Telecom.Licensing.Models”,“LicenseName:”总承包商“,”LicenseType:”{“$ref:”2“},“State:”{“$ref:”9“},“DateIssued:”2012-11-18T00:00:00.000”,“ValidFor:”1095,“IsActive:”false,“Id:”6}]编辑:从v1.3.1开始,Breeze现在支持继承。
问题可能是Breeze还不支持继承。这里有一个UserVoice。请投票表决。我们非常认真地对待这些建议
为了确认这是您的问题,您可以将结构展平,这样您就不需要继承,并查看问题是否消失。我认为,如果服务器到客户端之间的某个内容消失了,那么它将保留空数据列,这可能会破坏数据结构,并导致敲除绑定功能失调。
在选择最小化Breeze性能时,您可以根据需要将该属性置于较低级别。
1-BreezeWebApiConfig.cs级别
2-控制器级别
3-或HttGet水平
此属性适用于我:
var jsonx=Breeze.WebApi.BreezeConfig.Instance;
jsonx.GetJsonSerializerSettings().NullValueHandling=Newtonsoft.Json.NullValueHandling.Include
var serviceName = 'api/License';
// manager is the service gateway and cache holder
var manager = new breeze.EntityManager(serviceName);
var vm = {
activate: getLicenses,
title: 'Licenses',
licenses: ko.observableArray(),
includeExpired: ko.observable(false),
save: saveChanges,
show: ko.observable(false)
};
//vm.includeExpired.subscribe(getLicenses);
function getLicenses() {
log("querying Licenses", null, true);
var query = breeze.EntityQuery.from("GetLicenses");
//if (!vm.includeExpired()) {
// query = query.where("DateIssued.AddDays(ValidFor*-1)" > new Date(Date.now()));
//}
return manager
.executeQuery(query)
.then(querySucceeded)
.fail(queryFailed);
// reload vm.todos with the results
function querySucceeded(data) {
log("queried Licenses", null, true);
vm.licenses(data.results);
vm.show(true); // show the view
}
}
function queryFailed(error) {
log("Query failed: " + error.message, null, true);
}
function saveChanges() {
return manager.saveChanges()
.then(function () { log("changes saved", null, true); })
.fail(saveFailed);
}
function saveFailed(error) {
log("Save failed: " + error.message, null, true);
}
function log(msg, data, showToast) {
logger.log(msg, data, system.getModuleId(vm), showToast);
}
return vm;
//#endregion