实体框架 Datagridview 绑定

发布于 2024-12-09 09:08:16 字数 505 浏览 1 评论 0原文

我希望能够将 datagridview 绑定到实体框架数据库中存储的信息。我只想显示实体框架中存储的信息的子集,并且到目前为止一直使用类似于以下内容的命令来执行此操作。

Dim x = (from store as stores 
         in storeentity select store.name, 
            store.number, store.store_manager.name)
datagridview1.datasource = x

我现在希望能够做到这一点,但能够修改 datagridview 中返回的行并将更改返回到数据库。目前这不起作用,因为我返回的是匿名类型。 store.store_manager.name 是存储在由 FK 链接的另一个表中的属性。

任何人都可以提供有关如何执行此操作并仍然跟踪对象的任何指导吗?在过去的四个小时里,我尝试使用各种方法来实现此功能,但没有成功。

非常感谢任何帮助,非常感谢。

I want to be able to bind a datagridview to information stored in my entity framework database. I only want to display a subset of the information stored in my entity framework and have so far been carrying this out with a command similar to the following.

Dim x = (from store as stores 
         in storeentity select store.name, 
            store.number, store.store_manager.name)
datagridview1.datasource = x

I now want to be able to do this but be able to modify the returned rows in the datagridview and return the changes to the database. This doesnt work at the moment because I am returning an anonymous type. store.store_manager.name is a property stored in another table linked by a FK.

Can anyone offer any guidance on how to do this and still have it track the objects. I have spent the last four hours trying to get this workng using various methods and have had no luck.

Any help is greatly appreciated, many thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心房敞 2024-12-16 09:08:16

查看 ADO Entity Framework 创建不需要的实体密钥将实体框架对象绑定到 Datagridview C# 了解如何修改 EF 中视图的内容以便可以绑定和编辑。他们可能对你有帮助。

Have a look at ADO Entity Framework creating unwanted Entity Key and Binding Entity Framework objects to a Datagridview C# for how to modify the contents of a view in EF such that you can bind and edit. They might be helpful to you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文