Solved

LINQ join

Posted on 2014-03-02
6
255 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 63

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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 63

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

821 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