Select as a result field

2 posts, 0 answers
  1. ie
    ie avatar
    7 posts
    Member since:
    Feb 2007

    Posted 29 Oct 2010 Link to this post

    Hello guys,

    There is my sample DB:

    CREATE TABLE Product
    (Id uniqueidentifier NOT NULL PRIMARY KEY, Name nvarchar(50) NULL)
    GO
    CREATE TABLE Shop
    (Id uniqueidentifier NOT NULL PRIMARY KEY, Name nvarchar(50) NULL)
    GO
    CREATE TABLE Product2Shop
    (
        ProductId uniqueidentifier NOT NULL FOREIGN KEY REFERENCES Product (Id),
        ShopId uniqueidentifier NOT NULL FOREIGN KEY REFERENCES Shop (Id),
    )

    Sample code:
    class T
    {
        internal class ProductData
        {
            public string Name;
            public IEnumerable<string> Shops;
        }
     
        static void Main()
        {
            var list = new TestEntityDiagrams().Products.Select(
                x => new ProductData
                {
                    Name = x.Name,
                    Shops = x.Shops.Select(z => z.Name),
                }
            );
            foreach (var item in list)
            {
                Console.WriteLine("{0}: {1}", item.Name, string.Join(",", item.Shops));
            }
        }
    }

    And an exception as its result:

    Unhandled Exception: System.InvalidOperationException: An exception occured duri
    ng the execution of 'Extent<Sample.Product>.Select(x => new ProductData() {Name = x.Name, Shops = x.Shops.Select(z => z.Name)})'. See InnerException for more details.
     ---> System.NotImplementedException: VisitParameter/Exec
       at Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQueryImpl(Type type, Int32 elementAt, Object[] groupResolutionParamValues)
       at Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQuery(Type type, Int32 elementAt, Object[] groupResolutionParamValues)
       --- End of inner exception stack trace ---
       at Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQuery(Type type, Int32 elementAt, Object[] groupResolutionParamValues)
       at Telerik.OpenAccess.Query.ExpressionExecution.PerformDatabaseQuery[T](Piece`1 piece, Object[] grpVals)

    As a workaround I can convert to an array products:
    new TestEntityDiagrams().Products.ToArray().Select( ...

    But it will be nice to know, are you going to support this?

    Thanks, Ivan.
  2. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 05 Nov 2010 Link to this post

    Hi Ivan,

     in this very case, your woraround is not bad. I fewer products would be filtered, I would propose to use a .ToList() after the .Where(filter) method.
    Unfortunately, there has not been time yet for improvements in this area, but we will schedule a product enhancement for this case.

    Greetings,
    Thomas
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
Back to Top