0

We are using stored procedures quite significantly in our application and using LinqToSql to execute our procs and populate the List objects to be returned from DB access methods. However, we need to map some objects to another object type using AutoMapper and apparently AutoMapper extension Project().To requires a IQuryable whereas List is implements IEnumerable.

The source code:

public List<T> GetRecordsByTable<T>(MasterTables masterTable)
                {
                    var masters = new List<MasterData>();
                    using (_masterContext)
                    {
                        masters = (from o in _masterContext.procGetMasterDataList(masterTable.GetHashCode(), null, null, null, null, null)
                                   select new MasterData
                                   {
                                       Id = (long)o.iId,
                                       Table = (MasterTables)o.TableId,
                                       ItemValue = o.ItemValue,
                                       ItemText = o.ItemText,
                                       ParentItemValue = o.ParentItemValue,
                                       IsActive = o.IsActive,
                                       CustomField1 = o.CustomField1,
                                       CustomField2 = o.CustomField2,
                                       CustomField3 = o.CustomField3,
                                       IsDefault = o.IsDefault

                                   }).ToList();

                    }
                    return masters.All.Project().To<T>;

The compilation error:

System.Collections.Generic.List' does not contain a definition for 'Project' and no extension method 'Project' accepting a first argument of type 'System.Collections.Generic.List' could be found (are you missing a using directive or an assembly reference?) folder\Common\MasterDataRepository.cs 116 28 Omnicx.Data

Vikram
  • 6,865
  • 9
  • 50
  • 61

2 Answers2

3

You must use masters.AsQuerable().Project().To<T> in you return statement.

1

I suppose you have added following lines:

using AutoMapper;
using AutoMapper.QueryableExtensions;
Revolution88
  • 688
  • 5
  • 17
  • i have added them indeed. the challenge it seems is that List implement IEnumerable and Project().To requires IQueryable unless i've got something wrong. – Vikram Jun 17 '14 at 07:43