0

我有一个简单的模型,它是 Entity Framework 5 Code First,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 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;

    }


}

db 上下文返回适当的数据,但它不会出现在响应中。我没有足够的信誉点来发布图像,但许可证类型和状态在上下文的响应中。

但是,控制器的响应不包含前三个对象的 licensetype 对象。[{"$id":"1","$type":"Volt.Telecom.Licensing.Models.License, Volt.Telecom.Licensing.Models","LicenseName":"低电压","状态":{ "$id":"2","$type":"Volt.Telecom.Licensing.Models.State, Volt.Telecom.Licensing.Models","Name":"FL","LongName":"Florida", "IsActive":false,"Id":23},"DateIssued":"2012-11-18T00:00:00.000","ValidFor":1095,"IsActive":false,"Id":1},{" $id":"3","$type":"Volt.Telecom.Licensing.Models.License, Volt.Telecom.Licensing.Models","LicenseName":"Contractors",

这是客户端上的 home.js 文件。

定义(['服务/记录器'],功能(记录器){ var system = require('durandal/system');

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

});

关于为什么会发生这种情况以及仅针对前三个项目的任何想法,我们将不胜感激。我喜欢微风作为我们需要编写的一些水疗中心的潜力,但这引起了我的一些担忧。

更新 1 如果我在它工作的数据库中更改 LicenseType_id 的顺序,则初始顺序为 123123,如果更改为 312123 或 321123,则响应中的所有六个都是正确的 [{"$id":"1","$type": "Volt.Telecom.Licensing.Models.License, Volt.Telecom.Licensing.Models","LicenseName":"Low Voltage","LicenseType":{"$id":"2","$type":"Volt .Telecom.Licensing.Models.LicenseType, Volt.Telecom.Licensing.Models","Description":"General Contractors","IsActive":false,"Id":3},"State":{"$id": "3","$type":"Volt.Telecom.Licensing.Models.State, Volt.Telecom.Licensing.Models","Name":"FL","LongName":"Florida","IsActive":false ,"Id":23},"DateIssued":"2012-11-18T00:00:00.000","ValidFor":1095,"IsActive":false,"Id":1},{"$id":"4 ","$type":"Volt.Telecom.Licensing.Models.License, Volt.Telecom.Licensing.Models","LicenseName":"Contractors","LicenseType":{"$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.000","ValidFor":1095,"IsActive":false,"Id":2},{"$id ":"6","$type":"Volt.Telecom.Licensing.Models.License, Volt.Telecom.Licensing.Models","LicenseName":"General Contractors","LicenseType":{"$id":"7","$type":"Volt.Telecom.Licensing.Models.LicenseType, Volt.Telecom. Licensing.Models","Description":"Contractors","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。许可证,Volt.Telecom.Licensing.Models","LicenseName":"Low Voltage","LicenseType":{"$ref":"5"},"State":{"$id":"9"," $type":"Volt.Telecom.Licensing.Models。州,Volt.Telecom.Licensing.Models","Name":"CA","LongName":"California","IsActive":false,"Id":35},"DateIssued":"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":"General Contractors","LicenseType":{"$ref":"2"},"State":{"$ref":"9"},"DateIssued":"2012-11-18T00:00 :00.000","ValidFor":1095,"IsActive":false,"Id":6}]

4

2 回答 2

0

编辑:从 v 1.3.1 起,Breeze 现在支持继承。

问题可能是 Breeze 还不支持继承。这里有一个 UserVoice建议。请投票。我们非常重视这些建议。

要确认这是您的问题,您是否可以展平结构以便不需要继承并查看问题是否消失。

于 2013-02-27T19:59:31.823 回答
0

我认为,如果服务器到客户端之间有什么东西消失了,那是因为 Breeze 保留了空数据列,这可能会打乱数据结构并使敲除绑定功能失调。
在选择最小化 Breeze 性能时,您可以根据需要将该属性置于较低级别。
1 - BreezeWebApiConfig.cs 级别
2 - 控制器级别
3 - 或 HttGet 级别

此属性适用于我:
var jsonx = Breeze.WebApi.BreezeConfig.Instance;
jsonx.GetJsonSerializerSettings().NullValueHandling = Newtonsoft.Json.NullValueHandling.Include;

于 2013-03-23T19:51:37.123 回答