Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to add restriction to returned dataset?
Message
 
 
To
27/06/2014 14:00:42
General information
Forum:
ASP.NET
Category:
Entity Framework
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01602693
Message ID:
01602719
Views:
46
>>>Include is a function of either a DbQuery (http://msdn.microsoft.com/en-us/library/gg696785%28v=vs.113%29.aspx) or ObjectQuery(http://msdn.microsoft.com/en-us/library/bb738708%28v=vs.110%29.aspx). DbSet is a subclass of DbQuery (http://msdn.microsoft.com/en-us/library/system.data.entity.dbset%28v=vs.113%29.aspx). If you want to use include, you need to do so on either the DbSet or a DbQuery. AsQueryable and Where return IQueryable or IEnumerable respectively, not DbQuery.
>>>
>>>Also, the title of this thread have nothing to do with the actual contents. You aren't dealing with DataSets, and you are trying to include additional data to the results, not restrictions.
>>
>>Hi Rob,
>>
>>Do you know what the base class is doing with this code
>>
>>
>> public virtual IEnumerable<T> GetAll(params string[] includes)
>>        {
>>            var query = _dbSet.AsQueryable();
>>            includes.ToList().ForEach(x => query = query.Include(x));
>>
>>            return query;
>>        }
>>
>>?
>>
>>May be for now I'll not try to change this method. For my purpose I need to return not all rows from the table, but just the ones where parent_id = 0. So, I made a change in the first method which I am going to test and I am not sure what do to with the second method and if I need it or not.
>
>Include is for eager loading your navigation properties. It provides better performance when you need data from your navigation properties for multiple entities. I would change your code to the following:
>
>public virtual IEnumerable< T> GetAll(params string[] includes)
>        {
>            DbQuery query = _dbSet;
>            foreach(x in includes)
>                        query = query.Include(x);
>
>            return query;
>        }
>
This is our base class code.

For now I am trying to figure out what is the correct way to add that filter. We have Adapter and we have Repository. Should I try to add that filter in the Adapter class or in the Repository?

Also, I ran the application with only the first GetAll method in the repository changed. It didn't seem to be invoked (I put there a break point) and also I found that the code returned all the columns from a huge table (and 15 first rows).

Since I need this for the Index (list only), I want to somehow restrict this to only 2 (or 3) essential columns. Does it mean I need a different model (or ViewModel)?

BTW, your suggested change returned too many errors, so I left the original code in place.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform