【发布时间】:2014-08-01 14:15:53
【问题描述】:
我正在开发一个 asp.net mvc Web 应用程序,它连接到两个不同的数据库(我将它们命名为 dbA 和 dbB)。目前我需要创建一个 JSON 对象,其中包含来自不同表的值。
两个表如下:-
Table Technology from dbA,有以下字段:-
>> dbAID , Tag , db2ID
虽然来自 dbB 的 table Resource 有:-
>> Db2ID , Name
我有以下Action方法:-
public ActionResult AutoComplete(string term)
{
var tech = dbA.Technology.Where(a=>a.Tag.StartWith(term));//select all technology that have their tags start with passed term
var db2IDList = tech.Select(a=>a.db2ID).ToArray();//create a list of db2ID
var resource = dbB.Resource.Where(db2IdList.Contains(a=>a.dbBID));//get the resource based on the db2IDList
JsonResult j = newJsonResult();
//here I want the json to contain the Technology.Tag + ResoruceNane, where the join is based on the db2Id stored insdie the technology table
}
那么任何人都可以建议构造我的 JSON 对象的最佳方法是什么?
谢谢
【问题讨论】:
标签: asp.net asp.net-mvc json entity-framework-5 asp.net-mvc-5