繁体   English   中英

带有 DbSet 的 JsonResults

[英]JsonResults with DbSet

我想知道是否有办法将这两者结合起来。 有两个多个数据库集。 我已经尝试过使用相同的变量。 有任何想法吗?

     public JsonResult GetProductByPDLN(int pdlnId, int copcCode) 
        {
            _context.Configuration.ProxyCreationEnabled = false;
            var prod = _context.ProductLines
                .Where(pl => pl.Id == pdlnId)
                .Select(p => p.Products)
                .ToList();
            var copc = _context.ProfitCenters
                .Where(c => c.Id == copcCode)
                .Select(p => p.ProductLines)
                .ToList();
            return Json(prod && copc, JsonRequestBehavior.AllowGet);
        }

创建一个新的 class 或匿名。 这些方面的东西:

     public JsonResult GetProductByPDLN(int pdlnId, int copcCode) 
    {
        _context.Configuration.ProxyCreationEnabled = false;
        var prod = _context.ProductLines
            .Where(pl => pl.Id == pdlnId)
            .Select(p => p.Products)
            .ToList();
        var copc = _context.ProfitCenters
            .Where(c => c.Id == copcCode)
            .Select(p => p.ProductLines)
            .ToList();
        return Json(new {ProductLines = prod, ProfitCenters = copc}, JsonRequestBehavior.AllowGet);
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM