将LinqDataSource与View而不是Table一起使用 [英] Using LinqDataSource with a View instead of a Table

查看:126
本文介绍了将LinqDataSource与View而不是Table一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我一直在尝试使用带有View的LinqDataSource。选择操作很有效。但是,在更新和删除操作时遇到一些问题。



我设置了EnableUpdate =" true",配置了行为O / R设计器中View的使用存储过程进行更新/删除并设置参数。



试用要更新,它会因"实体的类型不正确"而失败。这是因为我使用的是View而不是Table吗?这是设计的吗?



有没有其他方法可以实现这一点 - 通过LinqDataSource更新更新2个表?

解决方案



您好,



我遇到了同样的问题并通过执行以下操作解决了这个问题。我不知道是否需要所有这些步骤,但它一直在为我工作。



1)在SQL视图中,确保包含'FROM'中的主键列'SQL语句中的表。



2)将此sql视图添加到'LINQ to SQL'设计器后,您将需要将该列标记为主键。 (选择设计器中的列,它是VS的属性窗口中的一个选项。)



3)在gridview的属性中,将DataKeyNames设置为您在设计器中设置为主键的列。



希望这会有所帮助..


< p class = MsoNormal style ="margin:0in 0in 10pt">






Hi,

I've been trying to use a LinqDataSource with a View. Select operations work great. However, having some trouble with the update and delete operations.

 

I have set EnableUpdate="true", configured the behavior of the View in the O/R designer to use stored procs for update/delete and have set the parameters.

 

On trying to update, it fails with 'The entity is not of the correct type'. Is this because I am using a View instead of a Table? Is this by design?

 

Is there an alternative to achieve this - update 2 tables through a LinqDataSource update?

解决方案

 

Hello,

 

I was running into this same issue and solved it by doing the following.  I don't know if all these steps are needed but it has been working for me.

 

1) In the SQL view make sure you include the primary key column from the 'FROM' table in the SQL statement.

 

2) After you add this sql view to the 'LINQ to SQL' designer you will need to mark that column as a primary key. ( select the column in the designer and it’s an option in the properties windows of VS. )

 

3) In the properties of the gridview set DataKeyNames to the column you set as primary key in the designer.

 

Hope this helps..

 

 

 

 

 


这篇关于将LinqDataSource与View而不是Table一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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