试图了解是否可以将FunctionImport用作路径的一部分。下面的示例不使用FunctionImport,并且可以按预期工作:
.../MyEntities('MyEntityKey')/MyChildEntities('MyChildEntityKey')/MyChildAction
但是,当我决定使用如下所示的FunctionImport时:
.../GetMyEntity('Param1')/MyEntityKey/MyChildEntities('MyChildEntityKey')/MyChildAction
我得到The number of keys specified in the URI does not match number of key properties for the resource 'MyEntity'
。
关于我所缺少的东西有什么想法吗?预先感谢。
这是我使用的课程;
public class MyServer : IUpdatableContext
{
public IQueryable<MyEntity> MyEntities
{
return GetMyEntities().AsQueryable();
}
[WebGet]
public IQueryable<MyEntity> GetMyEntity(string param1)
{
return GetMyEntities(param1).AsQueryable();
}
}
[DataServiceKey("MyEntityKey")]
public class MyEntity
{
public IEnumerable<MyChildEntity> MyChildEntities
{
get
{
return GetMyChildEntities().AsEnumerable();
}
}
}
[DataServiceKey("MyChildEntityKey")]
public class MyChildEntity
{
[EntityAction("MyChildAction")]
public Guid MyChildAction()
{
return ExecuteMyChildAction();
}
}
及其对应的.edmx文件:
<EntityContainer Name="MyServer" m:IsDefaultEntityContainer="true">
<EntitySet Name="MyEntities" EntityType="MyEntity" />
<FunctionImport Name="GetMyEntity" ReturnType="Collection(MyEntity)" EntitySet="MyEntities" m:HttpMethod="GET">
<Parameter Name="param1" Type="Edm.String" />
</FunctionImport>
</EntityContainer>
<EntityType Name="MyEntity">
<Key>
<PropertyRef Name="MyEntityKey" />
</Key>
<Property Name="MyEntityProp" Type="Edm.Int32" />
<NavigationProperty Name="MyChildEntity" Relationship="MyEntity_MyChildEntities" ToRole="MyChildEntities" FromRole="MyEntity"/>
</EntityType>
<EntityType Name="MyChildEntity">
<Key>
<PropertyRef Name="MyChildEntityKey" />
</Key>
<Property Name="MyChildEntityProp" Type="Edm.Int32" />
</EntityType>
<EntitySet Name="MyEntities" EntityType="MyEntity" />
<EntitySet Name="MyChildEntities" EntityType="MyChildEntity" />
<Association Name="MyEntity_MyChildEntities">
<End Type="MyEntity" Role="MyEntity" Multiplicity="1" />
<End Type="MyChildEntity" Role="MyChildEntities" Multiplicity="*" />
</Association>