我发布此聊天是因为它可以帮助某人:-
这是与支持团队的沟通:
我:
我们正在使用这个http://demo.easyquerybuilder.com/asp-net-mvc/我们正在从 sql 数据库加载数据,使用以下代码:
var eqService = new EqServiceProviderDb();
eqService.Paging.Enabled = true;
eqService.StoreQueryInSession = true;
eqService.SessionGetter = key => Session[key];
eqService.SessionSetter = (key, value) => Session[key] = value;
Korzh.EasyQuery.DataGates.SqlClientGate sqlGate = new Korzh.EasyQuery.DataGates.SqlClientGate();
eqService.ModelLoader = (model, modelName) =>
{
model.Clear();
sqlGate.ConnectionString = ConfigurationManager.AppSettings["our connection string to sql db here"].ToString();
sqlGate.Connected = true;
model.FillByDbGate(sqlGate, FillModelOptions.Default);
};
//For T-SQL use these settings
// var connection = context.Database.Connection;
eqService.Formats.SetDefaultFormats(FormatType.MsSqlServer);
eqService.Formats.UseSchema = false; //schema is not used in SQL Server CE
eqService.Connection = sqlGate.Connection;
eqService.Connection.ConnectionString = ConfigurationManager.AppSettings["our connection string to sql db here"].ToString();
//eqService.Connection.Open();
根据我们的场景,我们有地址簿表和客户表。客户表有两列 BossId 和 FriendId,与“Addressbook > Id”列具有 FK 关系。无论客户有朋友还是老板,我们都想要所有客户与朋友和老板的记录。我们可以通过在 sql 查询中使用左连接来获得所需的结果:
" Select cust.Name as CustomerName,frnd.Name as Friends,bos.Name as Boss from Customer as cust left join AddressBook as frnd on cust.FriendId=frnd.Id Left join AddressBook as Bos on cust.BossId=Bos.Id
"
支持团队:
所以,您只需在后面添加以下代码
model.FillByDbGate:
var tbl1 = model.Tables.FindByName("AddressBook");
var tbl2 = model.Tables.FindByName("Customer");
var link = model.Links.FindByTables(tbl1, tbl2);
link.LnkType = TableLink.LinkType.Left;
我:感谢您的回复,我知道这就是我们如何在 c# 代码中将左连接放置在两个表中,现在如果我尝试从两个表中获取数据,它将对它们应用左连接,但是我该如何选择连接(左/右/内)从 UI 页面动态?当我们尝试从两个表中获取数据时,简单查询是否提供任何选项来选择连接类型?例如,在我的最后一个场景中,如果我只想获取那些拥有 Boss 的客户的姓名和他们的老板的姓名(这里我必须应用内部联接)。
和我之前的 sql 查询一样
选择 cust.Name 作为 CustomerName,frnd.Name 作为 Friends,bos.Name 作为 Boss from Customer 作为 cust left join AddressBook as frnd on cust.FriendId=frnd.Id Left join AddressBook as Bos on cust.BossId=Bos.Id
我在同一张桌子上应用左连接两次来获得 frnd 和 Bos。
在 cust.FriendId=frnd.Id 上以 frnd 的身份左加入 AddressBook 在 cust.BossId=Bos.Id 上以 Bos 的身份左加入 AddressBook
是否可以在简单查询中从 UI 页面动态定义连接条件?
支持团队:
很遗憾,我们现在没有这样的 UI 控件/小部件,因此您需要自己实现它。
我们可以为将来的版本安排此功能,但我现在无法给出实施的确切时间框架。
总结:所以这个工具没有这个功能,我运气不好。