LINQ - Reference Collection object inside of Collection for Query

Does anybody know why I wouldn't have access to the eventSportsInfo object inside the LINQ query below?

I have two collections in code area below, the EventSportsInfo collection is referenced inside the TeamsSportsInfo collection.

Then in LINQ query we create a new instance of TeamsSportsInfo but when inside the query, I only have access to eventSportsInfo and none of its properties.  The "key" property in example is not available, intellisense only displays "Equals" and "ReferenceEquals".  Don't pay attention to what I'm assigning to it right now, just trying to get access to those properties.

This works just fine outside of the LINQ query, I have full access to both classes of properties when creating a new instance of TeamsSportsInfo.

I have tried many other examples and they all don't allow access.  

Any ideas?
public class EventSportsInfo
        public EventSportsInfo() { }

        public String Id { get; set; }
        public String Key { get; set; }
        public String DateCoverageType { get; set; }
        public String DateCoverageValue { get; set; }
        public String Status { get; set; }
        public Nullable<DateTime> StartDate { get; set; }
        public String  Week { get; set; }
        public String SeasonType { get; set; }

public class TeamSportsInfo
        public TeamSportsInfo() { }

        public Int32  Id { get; set; }         
        public String Key { get; set; }                                                         
        public Int32  PublisherId { get; set; } 
        public Int32  HomeSiteId { get; set; } 
        public String Score { get; set; }
        public String Alignment { get; set; }
        public String EventOutcome { get; set; }
        public Int32  DisplayNameId { get; set; } 
        public String EntityType { get; set; }                                                         
        public String FullName { get; set; }                                                            
        public String FirstName { get; set; }             
        public String LastName { get; set; }        
        public String Alias { get; set; }    
        public String Abbreviation { get; set; }
	public EventSportsInfo eventSportsInfo { get; set; }


                List<TeamsSportsInfo> teamsSportsInfo =
                    (from team in Root.Descendants("team")
                     let teamMetaData = team.Elements("team-metadata")
                     let teamName = teamMetaData.Elements("name")
                     let firstName = teamName.GetFirstElementsAttributeValueAsString("first")
                     let lastName = teamName.GetFirstElementsAttributeValueAsString("last")
                     select new TeamsSportsInfo
                        eventSportsInfo.Key = "",
                        Key = teamMetaData.GetFirstElementsAttributeValueAsString("team-key"),
                        Alignment = teamMetaData.GetFirstElementsAttributeValueAsString("alignment"),                        
                        FirstName = firstName,
                        LastName = lastName,
                        FullName = firstName + " " + lastName,

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi kruegerste;

You have a type O in the name TeamSportsInfo, in these line:

List<TeamsSportsInfo> teamsSportsInfo
select new TeamsSportsInfo

Should be:

List<TeamSportsInfo> teamsSportsInfo
select new TeamSportsInfo

There is an extra s after the m in Team.

Also eventSportsInfo is a getter/setter and you need to pass it a EventSportsInfo object and not to use it as an object of EventSportsInfo. So you will need to change the query to this to work here as well.

let eventInfo = new EventSportsInfo() { Key = "" }
select new TeamSportsInfo
    eventSportsInfo = eventInfo,


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kruegersteAuthor Commented:
thanks Fernando, that is sweet, that helps so much.  

Sorry about the typo, it came from me trying to put together a dummy example.  Our actual collection and queries are so huge that I try to provide a more simple example to keeps things from getting confusing.

Thanks again.
Fernando SotoRetiredCommented:
Is the issue solved?
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

kruegersteAuthor Commented:
kruegersteAuthor Commented:
correct, this worked perfectly, moving it into the Let statements as you suggested.

thanks again.
Fernando SotoRetiredCommented:
Not a problem, glad to help.  ;=)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.