[英]How to handle self join in EntityDataSource?
I wonder how to handle self join in EntityDataSource . 我想知道如何在EntityDataSource中处理自连接。
IF I have i query like this : 如果我有这样的查询:
SELECT b.degree_name ,c.degree_name as degree_next
FROM EMPDEGPROM a INNER JOIN DEGREEWORK b
ON a.degree_code=b.degree_code
INNER JOIN DEGREEWORK c
ON a.next_degree_code =c.degree_code
WHERE a.emp_num=6777
How to use this data source as EntityDataSource.? 如何使用此数据源作为EntityDataSource?
I try to do this but i can't get degree_next
我尝试执行此操作,但无法获得degree_next
<asp:EntityDataSource ID="EmpPromotionsDS" runat="server"
ConnectionString="name=CTX" DefaultContainerName="CTX" EnableFlattening="False"
EntitySetName="EMPDEGPROMs" EntityTypeFilter="EMPDEGPROM" Where="it.EMP_NUM =@emp_num" Include="DEGREEWORK" >
<WhereParameters>
<asp:SessionParameter Name="emp_num" SessionField="emp_num" DbType="Int32" />
</WhereParameters>
Create a view. 创建一个视图。
CREATE VIEW XXX AS
SELECT a.emp_num, b.degree_name ,c.degree_name as degree_next
FROM EMPDEGPROM a INNER JOIN DEGREEWORK b
ON a.degree_code=b.degree_code
INNER JOIN DEGREEWORK c
ON a.next_degree_code =c.degree_code
EF has no problem reading from views. EF从视图中读取没有问题。
If you want only readonly, you could drop the EntitySetName, EntityTypeFilter, Where and Include properties and use instead use the CommandText property. 如果只想只读,则可以删除EntitySetName,EntityTypeFilter,Where和Include属性,并改用CommandText属性。
If you want to use directly your entities, make sure you have a navigation property with a self reference and precise it in your include property. 如果要直接使用您的实体,请确保您拥有一个带有自我参考的导航属性,并在您的include属性中对其进行了精确调整。
<asp:EntityDataSource ID="EmpPromotionsDS" runat="server" ConnectionString="name=CTX" DefaultContainerName="CTX" EnableFlattening="False" CommandText= SELECT b.degree_name ,c.degree_name as degree_next FROM EMPDEGPROM a INNER JOIN DEGREEWORK b ON a.degree_code=b.degree_code INNER JOIN DEGREEWORK c ON a.next_degree_code =c.degree_code WHERE a.emp_num=@EmployeeId> <CommandParameters> <asp:ControlParameter Name="EmployeeId" ControlID="EmployeeIdTextBox" Type="Int32"/> </CommandParameters>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.