C# 如何使用entitydatasource在where子句中使用in语句
我想从entitydatasource下载完整的dropdownlist,但>>> 我有个问题C# 如何使用entitydatasource在where子句中使用in语句,c#,asp.net,C#,Asp.net,我想从entitydatasource下载完整的dropdownlist,但>>> 我有个问题 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:DropDown
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列
能帮忙吗
谢谢任何有相同问题的人都可以尝试此方法(请注意子选择中的'VALUE'关键字):
任何有相同问题的人都可以尝试此方法(注意子选择中的“VALUE”关键字):
列
Doctors.id
是否允许null
以及列DoctorsOfSections.doctorID是否允许null
?从消息中可以看出不匹配,您可能需要在SQL语句中使用COALESCE。COALESCE“”无法解析为有效的类型或函数。在简单标识符附近,列Doctors.id
是否允许null
以及列DoctorsOfSections.doctorID
是否允许null
?从消息中可以看出不匹配,您可能需要在SQL语句中使用COALESCE。COALESCE“”无法解析为有效的类型或函数。近乎简单的标识符,
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)"