ADO.NET 实体 - 需要帮助
我的数据库中有 3 个表,我从数据库创建了一个实体模型,它看起来像这样:
我想做的是将所有 3 个表绑定到 datagridview,并且我使用这样的查询
var result = from t in db.Transactions
from c in db.Categories
from a in db.Accounts
where t.FkCategoryID == c.CategoryID && t.FkAccountID == a.AccountID
select new { t.Description, t.BankReference, t.TransactionDate, c.CategoryName, a.AccountName, a.AccountNr };
效果很好。 但我需要能够使用绑定导航器工具栏来更新事务表
我无法做到这一点使用 linq 查询并将其绑定到 gridview。
有没有办法通过使用实体框架来实现这一点?我的意思是,当我仅将一个表绑定到绑定源时,我可以使用该工具栏删除更新并添加行,但我必须显示所有表,并且只能编辑事务表
提前致谢
i have 3 tables in my database and i created a entity model from database and it looks like this:
what im trying to do is to bind all 3 tables to datagridview and im using a query like this
var result = from t in db.Transactions
from c in db.Categories
from a in db.Accounts
where t.FkCategoryID == c.CategoryID && t.FkAccountID == a.AccountID
select new { t.Description, t.BankReference, t.TransactionDate, c.CategoryName, a.AccountName, a.AccountNr };
this works well.
But i need to be able to update the Transaction table by using the binding navigator toolbar
im not able to do that by using linq query and binding it to gridview.
Is there any way to accomplish that by using entity framework? I mean when i bind only one table to binding source im able to use that toolbar to delete update and add row but i have to show all tables and only be able to edit Transaction table
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个建议是为您的查询创建一个数据库视图并映射到该视图而不是连接的表。
One suggestion is to create a database view for your query and map to that instead of the joined tables.
我认为这是不可能的,因为您选择的是匿名类型而不是实体。因此网格中的记录与您的实体模型无关。您必须自行处理记录的删除和更新。
I don't think that this is possible because you are selecting annonymous type not the entity. So records in the grid are not related to your entity model. You have to handle record deletion and update by yourselves.