我很难理解从我控制的查询中返回 json 的选项,因为似乎有很多方法可以做到这一点。任何澄清将不胜感激。
我想从以下返回 json:
public class MyController : ApiController
{
private MyEntities context = new MyEntities();
public IQueryable <string> Get()
{
var query =
from MY_ENTITY_1 in my_entity_1
from MY_ENTITY_2 in my_entity_2
from MY_ENTITY_3 in my_entity_3
where
MY_ENITITY_1.something == MY_ENTITY_2.something
select new
{
Result1 = MY_ENTITY_1.FOO1,
Result2 = MY_ENTITY_2.FOO2,
Result3 = MY_ENTITY_3.FOO3
};
foreach (var myResults in query)
{
Console.WriteLine(myResults);
};
return myResults; // JSON?
}