[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

LINQ join

Posted on 2014-03-02
6
Medium Priority
?
280 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 Ageil
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 64

Accepted Solution

by:
Fernando Soto earned 2000 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 Ageil
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 64

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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

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!
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
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month18 days, 23 hours left to enroll

834 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