Solved

LINQ join

Posted on 2014-03-02
6
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

696 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