我正在使用breeze.js和ef 5.0,wcf数据服务5.6.0,knockout.js 3.0,一切正常。 上周我尝试将实体框架更新到版本6.0.2,并且没有办法让解决方案再次运行:每次我只收到导航绑定错误: es:“text:Soggetti()。Cognome” - >错误 es:“text:prova” - >确定
错误说:“Soggetti”未定义,但我可以在服务器的json中看到“Soggetti”对象。
那你有什么建议吗?
非常感谢 米歇尔
2013年12月21日更新:
服务器端代码-wcf数据服务使用实体framwork 6.0.2:
[JSONPSupportBehavior]
[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
[Serializable]
public partial class Entities : EntityFrameworkDataService<DL.mymap>
{
// 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("*", EntitySetRights.All);
// config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
}
这是html:
<table id="tbl_Legnatico" class="hovered">
<thead>
<tr style="font-weight: bold">
<th>Cod.Pratica</th>
<th>Data Pratica</th>
<th>Cognome</th>
<th>Nome</th>
<th>Data fine</th>
</tr>
</thead>
<tbody data-bind="foreach: itemsLegnatico" >
<tr>
<td data-bind="text: CodicePratica, click: $parent.selectLegnatico"></td>
<td data-bind="dateString: DataPratica, click: $parent.selectLegnatico"></td>
<td data-bind="text: Soggetti().Cognome, click: $parent.selectLegnatico"></td>
<td data-bind="text: Soggetti().Nome, click: $parent.selectLegnatico"></td>
<td data-bind="dateString: DataFineValidita, click: $parent.selectLegnatico"></td>
</tr>
</tbody>
</table>
这是使用breeze的js查询:
function vmLegnaticoSel(searchEntity, searchField, searchValue) {
$("#tbl_Legnatico_dettaglio").attr("style", "display: none;");
$("#tbl_Legnatico").attr("style", "display: block; width: 100%");
breeze.config.initializeAdapterInstance("dataService", "OData");
var dataService = new breeze.DataService({
serviceName: "http://localhost/BL/Entities.svc",
hasServerMetadata: true
});
var ms = new breeze.MetadataStore();
managerLegnatico = new breeze.EntityManager({
dataService: dataService,
metadataStore: ms
});
var query = null;
switch (searchEntity) {
case "Soggetti":
switch (searchField) {
case "Denominazione":
query = new breeze.EntityQuery()
.from("Legnatico")
.expand("Soggetti")
.where("Soggetti.Denominazione", "startsWith", searchValue);
break;
default:
}
break;
case "Legnatico":
if (searchValue == '')
searchValue = -111;
switch (searchField) {
case "CodicePratica":
query = new breeze.EntityQuery()
.from("Legnatico")
.expand("Soggetti")
.where("CodicePratica", "eq", searchValue);
break;
default:
}
break;
default:
}
$('#dialog').jqmShow();
managerLegnatico.executeQuery(query).then(function (data) {
vmLegnatico.itemsLegnatico(data.results);
}).fail(function (e) {
alert(e);
});
}
这是mvvm:
function vmLegnaticoInit()
{
vmLegnatico = (function () {
self.itemsLegnatico = ko.observableArray();
self.itemsSoggetti = ko.observableArray();
self.selectedLegnatico = ko.observable(),
self.deletedLegnatico = ko.observable(),
self.selectLegnatico = function (p) {
selectedLegnatico(p);
self.saveEdit = function (p) {;
mymap.managerSaveChanges(managerLegnatico);
};
return {
saveEdit: saveEdit,
itemsLegnatico: itemsLegnatico,
itemsSoggetti: itemsSoggetti,
selectedLegnatico: selectedLegnatico,
selectLegnatico: selectLegnatico,
})();
ko.applyBindings(vmLegnatico);
}