gpt4 book ai didi

javascript - Breeze js 调用元数据但不对服务器进行第二次调用

转载 作者:行者123 更新时间:2023-11-29 21:55:16 25 4
gpt4 key购买 nike

我正在使用 breeze js 和 asp.net odata Controller 编写一个 Angular 应用程序。 Breeze JS 成功地第一次调用服务器获取元数据,但没有进行第二次调用以实际获取数据。我在 Chrome 中看到的是

XHR finished loading: GET "http://localhost:31549/Odata/ClientInvestments/$metadata". 

返回

<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
<edmx:DataServices m:DataServiceVersion="3.0" m:MaxDataServiceVersion="3.0" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<Schema Namespace="Cadiz.Services.CadizOnline.Contracts.ClientInvestmentsService.DataContracts" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
<EntityType Name="ClientInvestment">
<Property Name="InvestmentNumber" Type="Edm.String" />
<Property Name="Initials" Type="Edm.String" />
<Property Name="InvestorFirstName" Type="Edm.String" />
<Property Name="InvestorLastName" Type="Edm.String" />
<Property Name="InvestorNumber" Type="Edm.String" />
<Property Name="BrokerCode" Type="Edm.String" />
<Property Name="UnclearedUnits" Type="Edm.Decimal" />
<Property Name="UnclearedMarketValue" Type="Edm.Decimal" />
<Property Name="BlockedUnits" Type="Edm.Decimal" />
<Property Name="BlockedMarketValue" Type="Edm.Decimal" />
<Property Name="TotalUnits" Type="Edm.Decimal" />
<Property Name="NavDate" Type="Edm.DateTime" />
<Property Name="NavCents" Type="Edm.Decimal" />
<Property Name="CurrentValue" Type="Edm.Decimal" />
<Property Name="FundName" Type="Edm.String" />
<Property Name="FundCode" Type="Edm.String" />
<Property Name="ProductName" Type="Edm.String" />
<Property Name="ProductCode" Type="Edm.String" />
<Property Name="ProductType" Type="Edm.String" />
<Property Name="EntityCode" Type="Edm.String" />
<Property Name="InvestmentType" Type="Edm.String" />
</EntityType>
<EntityType Name="ClientTransaction">
<Property Name="TransactionId" Type="Edm.Int32" />
<Property Name="BrokerCode" Type="Edm.String" />
<Property Name="InvestorNumber" Type="Edm.String" />
<Property Name="InvestmentNumber" Type="Edm.String" />
<Property Name="TransactionDate" Type="Edm.DateTime" />
<Property Name="Description" Type="Edm.String" />
<Property Name="GrossAmount" Type="Edm.Decimal" />
<Property Name="AgentFee" Type="Edm.Decimal" />
<Property Name="VatOnFees" Type="Edm.Decimal" />
<Property Name="TotalAgentFees" Type="Edm.Decimal" />
<Property Name="NetAmount" Type="Edm.Decimal" />
<Property Name="NavPrice" Type="Edm.Decimal" />
<Property Name="Units" Type="Edm.Decimal" />
<Property Name="Wauc" Type="Edm.Decimal" />
</EntityType>
<EntityContainer Name="Container" m:IsDefaultEntityContainer="true">
<EntitySet Name="ClientInvestments" EntityType="Cadiz.Services.CadizOnline.Contracts.ClientInvestmentsService.DataContracts.ClientInvestment" />
<EntitySet Name="ClientTransactions" EntityType="Cadiz.Services.CadizOnline.Contracts.ClientInvestmentsService.DataContracts.ClientTransaction" />
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>

然后什么都没有

我的 wep api 是这样配置的

public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapODataServiceRoute("Odata", "Odata/ClientInvestments", CreateClientInvestmentEdmModel());
config.Routes.MapODataServiceRoute("OdataCommission", "Odata/Commission", CreateCommissionEdmModel());
config.Routes.MapODataServiceRoute("OdataAssetsUnderManagement", "Odata/AssetsUnderManagement", CreateAssetsUnderManagementEdmModel());

config.Routes.MapHttpRoute(
name: "Reports",
routeTemplate: "api/reports/{action}",
defaults: new { controller = "Reports" }

);

config.Routes.MapHttpRoute(
name: "SecondaryMarket",
routeTemplate: "api/secondarymarket/{action}",
defaults: new { controller = "SecondaryMarket" }

);

config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}",
defaults: new { id = RouteParameter.Optional }
);

config.Formatters.Add(new CsvMediaTypeFormatter());
config.Formatters.Add(new ExcelMediaTypeFormatter());

config.MessageHandlers.Add(new LogRequestHandler());

config.Filters.Add(new HandleErrorFilter());

config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Default;
}

public static IEdmModel CreateClientInvestmentEdmModel()
{
var builder = new ODataConventionModelBuilder();

builder.Namespace = typeof(Cadiz.Services.CadizOnline.Contracts.ClientInvestmentsService.DataContracts.ClientInvestment).Namespace;
builder.EntitySet<Cadiz.Services.CadizOnline.Contracts.ClientInvestmentsService.DataContracts.ClientInvestment>(Cadiz.Services.CadizOnline.Contracts.ClientInvestmentsService.ClientInvestmentsServiceConstants.ClientInvestmentsQuery);
builder.EntitySet<Cadiz.Services.CadizOnline.Contracts.ClientInvestmentsService.DataContracts.ClientTransaction>(Cadiz.Services.CadizOnline.Contracts.ClientInvestmentsService.ClientInvestmentsServiceConstants.ClientTransactionsQuery);

return builder.GetEdmModel();
}

public static IEdmModel CreateCommissionEdmModel()
{
var builder = new ODataConventionModelBuilder();

builder.Namespace = typeof(Cadiz.Services.CadizOnline.Contracts.CommissionService.DataContracts.CommissionDetail).Namespace;
builder.EntitySet<Cadiz.Services.CadizOnline.Contracts.CommissionService.DataContracts.CommissionDetail>(Cadiz.Services.CadizOnline.Contracts.CommissionService.CommissionServiceConstants.CommissionDetailsQuery);
builder.EntitySet<Cadiz.Services.CadizOnline.Contracts.CommissionService.DataContracts.CommissionSummary>(Cadiz.Services.CadizOnline.Contracts.CommissionService.CommissionServiceConstants.CommissionSummaryQuery);

return builder.GetEdmModel();
}

public static IEdmModel CreateAssetsUnderManagementEdmModel()
{
var builder = new ODataConventionModelBuilder();

builder.Namespace = typeof(Cadiz.Services.CadizOnline.Contracts.AssetsUnderManagementService.DataContracts.ClientAsset).Namespace;
builder.EntitySet<Cadiz.Services.CadizOnline.Contracts.AssetsUnderManagementService.DataContracts.ClientAsset>(Cadiz.Services.CadizOnline.Contracts.AssetsUnderManagementService.AssetsUnderManagementServiceConstants.AssetsUnderManagementQuery);

return builder.GetEdmModel();
}
}

我的javascript是这样配置的

        breeze.config.initializeAdapterInstances({
dataService: "OData"
});

var dataService = new breeze.DataService({
serviceName: '/Odata/ClientInvestments'
});
var manager = new breeze.EntityManager({ dataService: dataService });
var query = new breeze.EntityQuery('ClientInvestments');
manager.executeQuery(query).then(function(data){
var results = data;
});

我的 odata Controller 看起来像

namespace Cadiz.Web.CadizOnline.Controllers.Odata.ClientInvestments
{
[Authorize]
public class ClientInvestmentsController : ODataController
{
#region Private Members

private readonly IClientInvestmentsService dataContext;

#endregion

#region Constructors

public ClientInvestmentsController(IClientInvestmentsService dataContext)
{
this.dataContext = dataContext;
}

#endregion

#region Methods

[EnableQuery(MaxOrderByNodeCount = 1)]
[ClaimsAuthorise(CadizSecurityConstants.Operations.Read, CadizSecurityConstants.Resources.Client)]
public IHttpActionResult Get()
{
var query = dataContext.ClientInvestments;
return Ok(query);
}

#endregion

#region Virtual Methods

protected override void Dispose(bool disposing)
{
if (disposing)
{
dataContext.Dispose();
}

base.Dispose(disposing);
}

#endregion
}
}

最佳答案

EntityManager 的 executeQuery 调用是异步的并返回一个 promise,所以你需要这样调用它:

manager.executeQuery(query).then(function(data) {
var results = data.results;
}

关于javascript - Breeze js 调用元数据但不对服务器进行第二次调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26787794/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com