Web API始终显示相同的值

时间:2018-12-21 10:20:49

标签: c# linq asp.net-core entity-framework-core asp.net-core-webapi

我有这样的电话。

当我将其称为“我的价值列表”时,它始终是相同的值。只有行是正确的。当我在SQL Management Studio中称其为5行时,在Postman中也为5行,但在所有行中值均相同

// GET: api/ablamm
[HttpGet("{schaf}")]
public IEnumerable<ablamm> Getablamm1([FromRoute]string schaf)
{
    return _context.ablamm.Where(s => s.schaf_nr == schaf);
}

这是输出结果:

[
{
    "schaf_nr": "SW063R",
    "lfd_nr": 1,
    "zum_widder_datum": "2014-07-06T00:00:00",
    "ablamm_datum": "2014-12-04T00:00:00",
    "abspaenn_datum": "2015-07-18T00:00:00",
    "lamm1_nr": "SM088B",
    "lamm2_nr": "",
    "lamm3_nr": "",
    "widder_nr": "S1009",
    "bemerkung": ""
},
{
    "schaf_nr": "SW063R",
    "lfd_nr": 1,
    "zum_widder_datum": "2014-07-06T00:00:00",
    "ablamm_datum": "2014-12-04T00:00:00",
    "abspaenn_datum": "2015-07-18T00:00:00",
    "lamm1_nr": "SM088B",
    "lamm2_nr": "",
    "lamm3_nr": "",
    "widder_nr": "S1009",
    "bemerkung": ""
},
{
    "schaf_nr": "SW063R",
    "lfd_nr": 1,
    "zum_widder_datum": "2014-07-06T00:00:00",
    "ablamm_datum": "2014-12-04T00:00:00",
    "abspaenn_datum": "2015-07-18T00:00:00",
    "lamm1_nr": "SM088B",
    "lamm2_nr": "",
    "lamm3_nr": "",
    "widder_nr": "S1009",
    "bemerkung": ""
},
{
    "schaf_nr": "SW063R",
    "lfd_nr": 1,
    "zum_widder_datum": "2014-07-06T00:00:00",
    "ablamm_datum": "2014-12-04T00:00:00",
    "abspaenn_datum": "2015-07-18T00:00:00",
    "lamm1_nr": "SM088B",
    "lamm2_nr": "",
    "lamm3_nr": "",
    "widder_nr": "S1009",
    "bemerkung": ""
},
{
    "schaf_nr": "SW063R",
    "lfd_nr": 1,
    "zum_widder_datum": "2014-07-06T00:00:00",
    "ablamm_datum": "2014-12-04T00:00:00",
    "abspaenn_datum": "2015-07-18T00:00:00",
    "lamm1_nr": "SM088B",
    "lamm2_nr": "",
    "lamm3_nr": "",
    "widder_nr": "S1009",
    "bemerkung": ""
}
]

但是当我在Management Studio中调用SQL Select时,它是正确的:

SW063R  1   2014-07-06  2014-12-04  2015-07-18  SM088B             S1009    
SW063R  2   2015-07-18  2015-09-18  2016-03-18  SW092G              1009    
SW063R  3   2016-03-18  2016-08-28  2017-02-25  SW101G  SM108B      1009    
SW063R  4   2017-02-25  2017-08-10  2018-01-13  SW107G  SW108G      1010    
SW063R  5   2018-01-13  2018-06-28  NULL        SW117G  SW118G      1010    

我的陈述有什么问题?

1 个答案:

答案 0 :(得分:-1)

尝试一下:

public List<ablamm> Getablamm1([FromRoute]string schaf)
    {
        List<ablamm> query = (_context.ablamm.Where(s => s.schaf_nr == schaf)).ToList();
        return query;
    }