Is is possible to define a subquery in a Model-Defined Function in Entity Framework? We have a situation where we have a customer object that has a history of names in an another table. We want to return the most current name as part of that customer object.
The model-defined function might look something like this:
<Function Name="CurrentName" ReturnType="Edm.String">
<Parameter Name="e" Type="Model.Customer"/>
<DefiningExpression>
(select top(1) n.LegalName from Entities.CustomerNames as n order by n.EffectiveDate Desc )
</DefiningExpression>
</Function>
Unfortunately, the above doesn't work. We get an error of:
The result type 'Edm.String' specified in the declaration of the function 'SNCCModel.CurrentLegalName' does not match the result type 'Transient.collection[Transient.rowtype(LEGAL_NAME,Edm.String(Nullable=True,DefaultValue=,MaxLength=512,Unicode=False,FixedLength=False))]' of the function definition
Any suggestions? Is this supposed to work? Sorry, but refactoring our data model to store the most recent name in the customer table is not an option.
Thanks, Rick