This is a migrated thread and some comments may be shown as answers.

Select as a result field

1 Answer 41 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
ie
Top achievements
Rank 1
ie asked on 29 Oct 2010, 11:58 PM
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.

1 Answer, 1 is accepted

Sort by
0
Thomas
Telerik team
answered on 05 Nov 2010, 06:10 PM
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
Tags
LINQ (LINQ specific questions)
Asked by
ie
Top achievements
Rank 1
Answers by
Thomas
Telerik team
Share this question
or