如何在where子句中使用实体数据源使用in语句

本文关键字:实体 in 语句 数据源 where 子句 | 更新日期: 2023-09-27 18:04:51

我想从entitydatasource完整的下拉列表,但是>>

i have a problem

CommandText="SELECT d.[firstName] FROM DentistEntities.Doctors AS d WHERE d.[id] IN (SELECT s.[doctorID] FROM DentistEntities.DoctorsOfSections AS s WHERE s.[sectionID] = 2)"

这是我的asp代码

<asp:DropDownList ID="doctorlist" runat="server" Width="172px" DataSourceID="EntityDataSource2" DataTextField="firstName" DataValueField="firstName">
</asp:DropDownList>
<asp:EntityDataSource ID="EntityDataSource2" runat="server" ConnectionString="name=DentistEntities" DefaultContainerName="DentistEntities" CommandText="SELECT d.[firstName] FROM DentistEntities.Doctors AS d WHERE d.[id] IN (SELECT s.[doctorID] FROM DentistEntities.DoctorsOfSections AS s WHERE s.[sectionID] = 2)">
</asp:EntityDataSource>

但是当我编译的时候出现了这个错误

元素类型"Edm"。Int32'和CollectionType 'Transient.collection[Transient.rowtype(doctorID,Edm.Int32(Nullable=True,DefaultValue=))]'不兼容。IN表达式只支持实体、标量和引用类型。在WHERE谓词第1行第69列附近

请提供帮助

谢谢

如何在where子句中使用实体数据源使用in语句

任何有同样问题的人都可以尝试这个(注意子选择中的'VALUE'关键字):

CommandText="SELECT d.[firstName] FROM DentistEntities.Doctors AS d WHERE d.[id] IN (SELECT VALUE s.[doctorID] FROM DentistEntities.DoctorsOfSections AS s WHERE s.[sectionID] = 2)"