Solved

LINQ join

Posted on 2014-03-02
6
251 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

17 Experts available now in Live!

Get 1:1 Help Now