Solved

LINQ join

Posted on 2014-03-02
6
250 Views
Last Modified: 2016-02-10
HI Experts,

I have this linq which is ok except one piece

myout.AddRange((from o in context.a
                join od in context.b on o.t_id equals od.id
                select new
                {
                    od.id,
                    od.mynavigationproperty.some_dte
                }).ToList()
                  .Select( od => new MyInfo
                   {
                       Tid = od.id,
                       Timestamp = od.mynavigationproperty.some_dte == null
                                     ? ""
                                     : od.some_dte.Value.ToString("yyyy/MM/dd HH:mm tt")
                   }).ToArray());

in first part   od.mynavigationproperty.some_dte is ok since it get via navigation property
but in second part Timestamp = od.mynavigationproperty.some_dte gives me error

"anonymous type does not contain definition for mynavigationproperty ......."

How do I fix it ?

Thanks.
0
Comment
Question by:fpoyavo
  • 2
  • 2
  • 2
6 Comments
 
LVL 27

Expert Comment

by:Sammy
ID: 39899723
Your first select is projecting to an anonymous.
change it to

 select new REPLACE WITH YOUR CLASS NAME
                {
                    od.id,
                    od.mynavigationproperty.some_dte
                }).ToList()
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39900387
Hi fpoyavo;

Please post the class MyInfo and the SQL data type of some_dte in this statement, od.mynavigationproperty.some_dte. Also what is the relationship between od and some_dte in the database for example

od           some_dte
One    to    One
One    to    Many
Many   to    Many

Open in new window

0
 
LVL 27

Expert Comment

by:Sammy
ID: 39900938
Fernando,
Linq doesn't necessarily mean databases. The framework have no idea about the properties you are trying to read when it sees you projecting into an Anonymous.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 62

Expert Comment

by:Fernando Soto
ID: 39901013
@sammy1971;

This question is a follow up question on a query for Linq to Entities.
0
 
LVL 1

Author Comment

by:fpoyavo
ID: 39901690
Hi guys,

I actually fixed but now I would do groupby od.id  How I do that ? Thanks a lot.

myout.AddRange((from o in context.a
                join od in context.b on o.t_id equals od.id
                select new
                {
                    od.id,
                    od.mynavigationproperty.some_dte
                }).ToList()
                  .Select( od => new MyInfo
                   {
                       Tid = od.id,
                       Timestamp = od.mynavigationproperty.some_dte == null
                                     ? ""
                                     : od.some_dte.Value.ToString("yyyy/MM/dd HH:mm tt")
                   }).ToArray());
0
 
LVL 1

Author Comment

by:fpoyavo
ID: 39901858
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now