开发者

Basic and simple linq to sql, not sure what's wrong

开发者 https://www.devze.com 2023-02-25 02:00 出处:网络
I a have a simple linq to sql query and for some reason the .take() doesn\'t work. I tried to add skip() as well thinking that maybe it needed some starting point from where to take the records but th

I a have a simple linq to sql query and for some reason the .take() doesn't work. I tried to add skip() as well thinking that maybe it needed some starting point from where to take the records but the results are still same and rather than taking only 10 recor开发者_StackOverflowds, it takes all 240 records.

Would appreciate if somebody can tell me what's going on. Thanks in advance.

The code is:

var types = (from t in EventTypes.tl_event_types
                        select new
                        {
                            type_id = t.event_type_id,
                            type_name = t.type_name
                        }).Take(10);


I'm assuming that by naming conventions that EventTypes is your object. You need to select from your data context... So

var types = (from t in dataContext.EventTypes.tl_event_types
                    select new
                    {
                        type_id = t.event_type_id,
                        type_name = t.type_name
                    }).Take(10);

should work.

0

精彩评论

暂无评论...
验证码 换一张
取 消