none
how to get many result in sp RRS feed

  • Question

  • hi

    i use EF in vs2010

    i have a sp that reurn 2 result

    please help me how to get them with Linq

    thanks

    Friday, November 2, 2012 1:22 PM

Answers

  • Hi Vahidbakhtiary,

    It seems like your stored procedure return multiple result sets, which Entity Framework does not directly support. But, it is possible to get this behavior in EF4 by using the Translate method and ExecuteStoreReader. However, the Entity Framework team has provided sample utilities, the EFExtensions, on the MSDN Code Gallery that will enable you to consume multiple resultsets. There are other features provided by the EFExtensions, such as renaming columns (to solve a problem which was discussed earlier in this whitepaper). To learn more and download the extensions, visit http://code.msdn.microsoft.com/EFExtensions. Note that the extensions and other samples provided on the Code Gallery, while very useful, are not supported by Microsoft. Please refer to this page: http://msdn.microsoft.com/en-us/data/gg699321.aspx

    Best Regards,


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Alexander Sun Thursday, November 22, 2012 6:34 AM
    Tuesday, November 6, 2012 6:16 AM

All replies

  • Hi Vahidakhtiary,

    Welcome to the MSDN forum.

    Could you please let me know more specific information? Do you mean you want to use a Linq to replace the stored procedure? What is the two result? Two records of same entity types or different types? Or just two CLR types?

    Best Regards,


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    Monday, November 5, 2012 6:50 AM
  • thanks for your answer

    i put my sp

    create proc sp_com_ReturnValue
    @CharPorts char(5)
    ,@SDate char(6)
    ,@EDate char(6)
    as
    IF dbo.PortSelect(@CharPorts,'B')=1
    BEGIN
    SELECT     CShips.CShipFarsiName, LineVoyage.LineVoyageVoyage, 
    		dbo.FormatCharDate(VHFForm.VHFEoDate) as LinTempExitDate,
    		dbo.FormatCharTime(VHFForm.VHFEntTime) as LinTempExitTime, 
    	        	VHFForm.VHFGoodsName, 	
    	              CASE SUBSTRING(VHFForm.VHFWhat, 3, 1)  when 0 then 'False' else 'True' end  AS Need, 
    	              CASE SUBSTRING(VHFForm.VHFWhat, 2, 1)  when 0 then 'False' else 'True' end  AS Loading, 
    	              CASE SUBSTRING(VHFForm.VHFWhat, 1, 1)  when 0 then 'False' else 'True' end  AS Dchsg, 
    		 'B' as PortName
    	FROM         [192.168.0.24].BCom.dbo.LineVoyage LineVoyage INNER JOIN
    	                      [192.168.0.24].BCom.dbo.LinTempExit LinTempExit ON LineVoyage.LineVoyageID = LinTempExit.LineVoyageID INNER JOIN
    	                      [192.168.0.24].BCom.dbo.CShips CShips ON LineVoyage.CShipCode = CShips.CShipCode INNER JOIN
    	                      [192.168.0.24].BCom.dbo.VHFForm VHFForm ON LineVoyage.LineVoyageID = VHFForm.LineVoyageID
    	WHERE     (LineVoyage.LineVoyageState = '1') AND 
    		(VHFForm.VHFEoDate > @SDate) AND (VHFForm.VHFEoDate <=@EDate) --and  LineVoyageAgent='51'
    	ORDER BY VHFEoDate
    end
    IF dbo.PortSelect(@CharPorts,'E')=1
    BEGIN
    SELECT     CShips.CShipFarsiName, LineVoyage.LineVoyageVoyage, 
    		dbo.FormatCharDate(VHFForm.VHFEoDate) as LinTempExitDate,
    		dbo.FormatCharTime(VHFForm.VHFEntTime) as LinTempExitTime, 
    	        	VHFForm.VHFGoodsName, 	
    	              CASE SUBSTRING(VHFForm.VHFWhat, 3, 1)  when 0 then 'False' else 'True' end  AS Need, 
    	              CASE SUBSTRING(VHFForm.VHFWhat, 2, 1)  when 0 then 'False' else 'True' end  AS Loading, 
    	              CASE SUBSTRING(VHFForm.VHFWhat, 1, 1)  when 0 then 'False' else 'True' end  AS Dchsg, 
    		 'E' as PortName
    	FROM         [192.168.0.24].ECom.dbo.LineVoyage LineVoyage INNER JOIN
    	                      [192.168.0.24].ECom.dbo.LinTempExit LinTempExit ON LineVoyage.LineVoyageID = LinTempExit.LineVoyageID INNER JOIN
    	                      [192.168.0.24].ECom.dbo.CShips CShips ON LineVoyage.CShipCode = CShips.CShipCode INNER JOIN
    	                      [192.168.0.24].ECom.dbo.VHFForm VHFForm ON LineVoyage.LineVoyageID = VHFForm.LineVoyageID
    	WHERE     (LineVoyage.LineVoyageState = '1') AND 
    		(VHFForm.VHFEoDate > @SDate) AND (VHFForm.VHFEoDate <=@EDate) --and  LineVoyageAgent='51'
    	ORDER BY VHFEoDate
    	end
    	

    and when i add function import in EF and create ComplexType

    just retrun the select first

    note my sp is in server 192.168.0.35

    please help me

    Monday, November 5, 2012 3:59 PM
  • Hi Vahidbakhtiary,

    It seems like your stored procedure return multiple result sets, which Entity Framework does not directly support. But, it is possible to get this behavior in EF4 by using the Translate method and ExecuteStoreReader. However, the Entity Framework team has provided sample utilities, the EFExtensions, on the MSDN Code Gallery that will enable you to consume multiple resultsets. There are other features provided by the EFExtensions, such as renaming columns (to solve a problem which was discussed earlier in this whitepaper). To learn more and download the extensions, visit http://code.msdn.microsoft.com/EFExtensions. Note that the extensions and other samples provided on the Code Gallery, while very useful, are not supported by Microsoft. Please refer to this page: http://msdn.microsoft.com/en-us/data/gg699321.aspx

    Best Regards,


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Alexander Sun Thursday, November 22, 2012 6:34 AM
    Tuesday, November 6, 2012 6:16 AM