Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to add restriction to returned dataset?
Message
De
27/06/2014 13:06:55
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Entity Framework
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01602693
Message ID:
01602698
Vues:
46
This message has been marked as a message which has helped to the initial question of the thread.
>I am getting the following error now:
>
>Error 35 'System.Linq.IQueryable SysManager.Models.ItemTree' does not contain a definition for 'Include' and no extension method 'Include' accepting a first argument of type 'System.Linq.IQueryable SysManager.Models.ItemTree ' could be found (are you missing a using directive or an assembly reference?) C:\_Siriusware\Main\SysManager\SysManager.Repository\ItemTreeRepository.cs 25 58 SysManager.Repository
>
>These are the changes I tried to implement
>
>
> public override IEnumerable<ItemTree> GetAll()
>        {
>            return _dbSet.Where(x=>x.parent_id==0);
>        }
>
>        public override IEnumerable<ItemTree> GetAll(params string[] includes)
>        {
>            var query = _dbSet.Where(x=>x.parent_id==0).AsQueryable();
>            includes.ToList().ForEach(x => query = query.Include(x));
>
>            return query;
>        }
>
>
>The first one seems to compile OK, but the second has include underlined. What should I do to make this work?
>
>Thanks in advance.
>
>
>>Hi everybody,
>>
>>We have RepositoryBase class with the following two methods:
>>
>>
>> public virtual IEnumerable<T> GetAll()
>>        {
>>            return _dbSet;
>>        }
>>
>>        public virtual IEnumerable<T> GetAll(params string[] includes)
>>        {
>>            var query = _dbSet.AsQueryable();
>>            includes.ToList().ForEach(x => query = query.Include(x));
>>
>>            return query;
>>        }
>>
>>
>>And I have a repository class for my table which has just the following code:
>>
>>
>>public class ItemTreeRepository : RepositoryBase<ItemTree>, IItemTreeRepository
>>    {
>>        public ItemTreeRepository(ISysManagerContext context) : base(context)
>>        {           
>>        }
>>}
>>
>>
>>I need to add the following restriction to the returned dataset for GetAll methods (parent_id = 0) (e.g. I only want to return parent nodes).
>>
>>I am a bit confused as what do I need to add to my class to make this happen.
>>
>>Thanks in advance.
>>
>>I actually, I think, figured code for the first method (the simple GetAll), now trying to figure out where include extension came from...
>>
>>How can I know which using to include for custom extension?

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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform