0
我使用來自Microsoft.OData.Core(et al)的ODataLib v7.1.1位構建OData服務。我在使用ODataUriParser.ParsePath()使用縮短的關鍵詞謂詞URL格式時遇到了問題。 (相對)URL Company('Comp1')/ Customer(1)「引發異常」URI中指定的鍵數與資源'Test.Customer'的鍵屬性數不匹配「。OData縮短的關鍵謂詞支持
該模型是非常簡單的,我不明白爲什麼這是行不通的。其他格式的網址工作(「Company('Comp1')」,「Customer(CompanyId ='COMP1',CustNum = 1)」)。
我已經將模型構建器代碼放在$元以下的輸出中。任何幫助,將不勝感激。謝謝!
-Erik
var result = new EdmModel();
var company = new EdmEntityType("Test", "Company");
var companyKey1 = company.AddStructuralProperty("CompanyId", EdmPrimitiveTypeKind.String, false);
company.AddKeys(
companyKey1
);
result.AddElement(company);
var customer = new EdmEntityType(NS, "Customer");
var customerKey1 = customer.AddStructuralProperty("CompanyId", EdmPrimitiveTypeKind.String, false);
var customerKey2 = customer.AddStructuralProperty("CustNum", EdmPrimitiveTypeKind.Int32, false);
customer.AddKeys(
customerKey1,
customerKey2
);
result.AddElement(customer);
var navCompanyCustomer = company.AddUnidirectionalNavigation(
new EdmNavigationPropertyInfo()
{
ContainsTarget = true,
Name = "Customer",
Target = customer,
TargetMultiplicity = EdmMultiplicity.Many
});
var customerRefToCompany = customer.AddUnidirectionalNavigation(
new EdmNavigationPropertyInfo()
{
ContainsTarget = false,
Name = "Company",
Target = company,
TargetMultiplicity = EdmMultiplicity.One,
DependentProperties = new[] { customerKey1 },
PrincipalProperties = new[] { companyKey1 }
});
var container = new EdmEntityContainer("Test", "DefaultContainer");
result.AddElement(container);
container.AddEntitySet("Company", company);
container.AddEntitySet("Customer", customer);
return result;
<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
<edmx:DataServices>
<Schema Namespace="Test" xmlns="http://docs.oasis-open.org/odata/ns/edm">
<EntityType Name="Company">
<Key>
<PropertyRef Name="CompanyId" />
</Key>
<Property Name="CompanyId" Type="Edm.String" Nullable="false" />
<NavigationProperty Name="Customer" Type="Collection(Test.Customer)" ContainsTarget="true" />
</EntityType>
<EntityType Name="Customer">
<Key>
<PropertyRef Name="CompanyId" />
<PropertyRef Name="CustNum" />
</Key>
<Property Name="CompanyId" Type="Edm.String" Nullable="false" />
<Property Name="CustNum" Type="Edm.Int32" Nullable="false" />
<NavigationProperty Name="Company" Type="Test.Company" Nullable="false">
<ReferentialConstraint Property="CompanyId" ReferencedProperty="CompanyId" />
</NavigationProperty>
</EntityType>
<EntityContainer Name="DefaultContainer">
<EntitySet Name="Company" EntityType="Test.Company" />
<EntitySet Name="Customer" EntityType="Test.Customer" />
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>