在EF(VB.Net)中创建动态查询 [英] Create Dynamic Query in EF (VB.Net)

查看:119
本文介绍了在EF(VB.Net)中创建动态查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我用一个例子来解释我的问题。 (实体框架和VB.net 2012)



我的表单中有两个DataGridViews。第一个DGV从SQL(数据源)中的表填充,第二个DGV数据源是SQL中的空表(By Entitiy Faramwork)。用户必须从DGV1中选择一些记录,然后通过点击一个按钮将它们发送到DGV2。



有什么问题?



当用户从DGV1向DGV2发送一些记录时,传输的记录必须从DGV1中消除,而不对SQL表进行任何更改。最后的更改将通过单击按钮来保存。



如何在不对SQL中的主数据进行任何更改的情况下在DGV1和DGV2数据源之间创建此关系?


我可以在MS Access中轻松完成这项工作,但我不能在EF中这样做。



任何帮助都会很大赞。

Hi
I explain my problem with an example. (Entity Framework and VB.net 2012)

I have two DataGridViews in my form. first DGV populated from a table in SQL (datasource) and second DGV datasource is an empty table in SQL (By Entitiy Faramwork). user must selects some records from DGV1 and sends them to DGV2 by clicking on a button.

and what is the problem?

when user sends some records from DGV1 to DGV2, transferred records must eliminate from DGV1 without any change on SQL tables. changes finally will be saved by a button clicking.

How can create this relation between DGV1 and DGV2 datasources with out any change to main data in SQL??

I can do this easily in MS Access but i cant do this in EF.

Any help will be greatly appreciated.

推荐答案

如果你想一想,这很容易。由于您需要将数据保存在SQL中,因此必须将其数据保存在DataTable中。然后将DGV1绑定到它。当您在DGV1中选择要转移并点击按钮的记录时,您只需获取所选行中的数据并使用它创建新的EF实体,然后从DataTable中删除该行。然后,您可以将新实体添加到集合中并将DGV2绑定到它。
It''s easy if you think about it. Since you need to keep the data in SQL, you have to keep it''s data in a DataTable. You then bind DGV1 to it. When you select the record in DGV1 to tranfer and hit the button, you simply take the data in the selected row and create new EF entities with it, then remove that row from the DataTable. You can then add the new entities to a collection and bind DGV2 to it.


这篇关于在EF(VB.Net)中创建动态查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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