On Wed, 2010-05-19 at 20:54 -0700, xanadont wrote:
> Is it possible to project types generated by DbLinq to other types?
> For example:
> 
> var mine = from i in Context.Items
>   select new MyItem
>   {
>     Id = i.ID,
>     Value = i.Value
>   };
> 
> I'm getting exceptions where the Message is simply "New".  Is there a
> work around for this?

Can you provide a full stack trace? This should work, with the exception
that you can't use 'new' to create new Entity instances; see
ExpressionDispatercher.Analyzer.cs:AnalyzeSelect():

        protected virtual Expression AnalyzeSelect(IList<Expression> 
parameters, BuilderContext builderContext)
        {
            // just call back the underlying lambda (or quote, whatever)
            Expression ex = Analyze(parameters[1], parameters[0], 
builderContext);

            // 
http://social.msdn.microsoft.com/Forums/en-US/linqprojectgeneral/thread/1ce25da3-44c6-407d-8395-4c146930004b
            if (ex.NodeType == ExpressionType.MemberInit &&
                    
builderContext.QueryContext.DataContext.Mapping.GetMetaType(ex.Type) != null)
                throw new NotSupportedException(
                    string.Format("Explicit construction of entity type '{0}' 
in query is not allowed.",
                        ex.Type.FullName));
            TableExpression tableExpression = parameters[0] as TableExpression;
            if (tableExpression != null && 
builderContext.CurrentSelect.Tables.Count == 0)
                RegisterTable(tableExpression, builderContext);
            return ex;
        }

 - Jon


-- 
You received this message because you are subscribed to the Google Groups 
"DbLinq" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/dblinq?hl=en.

Reply via email to