简体   繁体   English

尽管我使用Take()方法,但EF Core返回所有数据

[英]Despite I use Take() method, EF Core return all data

I have a view in my DB. 我在数据库中有一个视图。 I have created model of view and call it with EF Core . 我已经创建了视图模型,并使用EF Core调用。 There are 16 rows in view. 视图中有16行。 When I call it with EF Core and use Take(10) it returns 10 rows but I look DBSet all rows shows there. 当我使用EF Core调用它并使用Take(10)它返回10行,但我看DBSet那里显示的所有行。 For detail here is my code 详细信息是我的代码

[Table("my_view", Schema ="dbo")]
public class MyView
{

    [Column("id")]
    [Key]
    public int Id { get; set; }

    [Column("name")]
    public string Name { get; set; }

}

in my action: 在我的行动中:

public JsonResult Index()
{
    using (var context = new CCContext())
    {
        var listOfData = context.MyView
                            .AsQueryable().Take(10).ToList();
        return Json(listOfData);
    }
}

PS. PS。 For some problem I couldn't upload screen of result.( https://m.imgur.com/gallery/xmP3q32 ) 对于某些问题,我无法上传结果屏幕。( https://m.imgur.com/gallery/xmP3q32

https://imgur.com/a/xmP3q32 https://imgur.com/a/xmP3q32

If you mean context.MyView contains all rows, then you are right. 如果您的意思是context.MyView包含所有行,那么您是对的。 Because that is a representation of the table in the DB. 因为那是数据库中表的表示。 However, in your example listOfData should contain only 10 rows. 但是,在您的示例listOfData应仅包含10行。 If so, then this is as it should be expected. 如果是这样,那么这是应该预期的。

If the above does not answer your question, please give some more insight and also, what DB provider are you using with EF? 如果以上内容不能解决您的问题,请提供更多的见解,此外,您在EF中使用哪个数据库提供商?

For clarification: The data is not there untill you ask a debugger (or code) to fetch it for you. 为了澄清起见: 直到您要求调试器(或代码)为您获取数据后,数据才存在。 The only reason you see it is because you ask the debugger to show its contents, and therefor it fetches its contents. 看到它的唯一原因是因为您要求调试器显示其内容,并因此获取其内容。 It wont if you wont ask it to. 如果您不要求它,它就不会。

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

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