如何将数据透视表与edmx绑定 [英] How to bind pivot table with edmx

查看:111
本文介绍了如何将数据透视表与edmx绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用visual studio 2010和Entity Framework(EF)。我正在使用存储过程从数据库中检索数据并通过实体模型绑定到Gridview。当我在Sql Query中执行此存储过程时,它会返回动态生成的
列。即,执行(@PivotTableSQL)。 @PivotTableSQL包含动态生成的select语句。以下是我的代码  存储过程。


但是,要创建复杂类型,请从实体模型浏览器窗口 - > 添加功能导入窗口 - >复杂 - >获取列信息,  "所选存储过程不返回任何列。"消息显示。请给我
一个解决方案,如何添加功能导入和获取列信息(创建复杂类型)或任何其他替代解决方案。这个阻止了我的进一步发展。提前致谢。


  alter PROCEDURE spGetQuestGrid



  @QID as int


$
AS

BEGIN

  SET NOCOUNT OFF

  SET FMTONLY OFF

 声明@optId VARCHAR(10)

  DECLARE @PivotColumnHeaders VARCHAR(MAX)

  DECLARE @PivotTableSQL NVARCHAR(MAX)

 

 设置@optId =(从QuestOptions中选择DISTINCT Optid,其中QID = @QID) 

 

  SELECT @PivotColumnHeaders = COALESCE(@PivotColumnHeaders + '[' +铸造(标题为varchar)+ ']',

     &NBSP ;   '[' +铸造(标题为varchar)+ ']')

         FROM OptionsDetail其中OptId = @ optId

 

  SET @PivotTableSQL ='select * from(选择  Caption,Optid 来自OptionsDetail)作为数据表

  ;   & NBSP;   PIVOT

         (min(Optid)FOR Caption IN('+ @PivotColumnHeaders +'))as Colltable' 


 

 执行(@PivotTableSQL) 

 

END

解决方案

Hello Mohit,


 


欢迎来到MSDN论坛,感谢您在此发帖。


根据您的描述,我认为您的问题的关键点是将复杂类型映射到存储过程的结果。关于这一点,这里有一篇关于如何做到这一点的文章,其中有一些代码。请阅读如下:


实体数据模型(EDM)支持使用存储过程对
的属性进行数据修改的ComplexType 。本主题中提供的示例将存储过程支持添加到主题中定义的数据模型
如何:定义具有复杂类型的模型


此示例中使用的存储过程在商店模式定义语言(SSDL)中指定。
功能元素标识数据库中可访问的存储过程。存储过程指定用于创建,更新和删除
实例的三个修改函数 CAddress
ComplexType


I am using visual studio 2010 and with Entity Framework(EF). I am retriving data from database and binding into Gridview thru Entity Model, using stored procedures. when i execute this Stored procedure in Sql Query, its returns columns which is generated dynamically. ie., Execute (@PivotTableSQL). @PivotTableSQL contains dynamically generated select statement. Below is my code of the Stored procedure.

But, To create Complex Type, from the Entity model browser window -> Add Function import window -> Complex --> Get Columns Information,  "The selected stored procedure return no columns." message is displayed. Please give me a solution, how to add function import and Get Column information(create complex Type) or any other alternate solution detaily. This one stopped my further development. Thanks in advance.

 alter PROCEDURE spGetQuestGrid
(
 @QID as int
)
AS
BEGIN
 SET NOCOUNT OFF
 SET FMTONLY OFF
 Declare @optId varchar(10)
 DECLARE @PivotColumnHeaders VARCHAR(MAX)
 DECLARE @PivotTableSQL NVARCHAR(MAX)
 
 set @optId = (select DISTINCT Optid from  QuestOptions where QID = @QID) 
 
 SELECT @PivotColumnHeaders = COALESCE(@PivotColumnHeaders + ', [' + cast(Caption as varchar) + ']' ,
        '[' + cast(Caption as varchar)+ ']')
        FROM OptionsDetail where OptId = @optId
 
 SET @PivotTableSQL = 'select * from (select  Caption,Optid  from OptionsDetail ) as datatable
        PIVOT
         ( min(Optid) FOR Caption IN ( '+ @PivotColumnHeaders + '))as Colltable' 
 
 Execute (@PivotTableSQL)  
 
END

解决方案

Hello Mohit,

 

Welcome to the MSDN Forum and thanks for posting here.

According to your description, I think the keypoint of your issue is the result mapping complex type to stored procedure. About this, here is an article about how to do this, in which there are some codes. Please read it as below:

The Entity Data Model (EDM) supports use of stored procedures for data modification to properties of the ComplexType. The example provided in this topic adds stored procedure support to the data model defined in the topic How to: Define a Model with Complex Type.

The stored procedures used in this example are specified in store schema definition language (SSDL). The Function element identifies the stored procedures accessible in the database. Stored procedures are specified for three modification functions used to create, update, and delete instances of the CAddress ComplexType.


这篇关于如何将数据透视表与edmx绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆