views:

14

answers:

0

Hello,

I am having an issue with querying the entity framework (.net 4.0).

I have the following:

public IQueryable<Comment> GetComments(string section, int sectionId)
{
    var query = from comm in ObjectContext.Comments.Where(id => id.SectionId == sectionId && id.CommentSection == section)
        select comm;
    return query;
}

Now, my Comments table FK's to a Users table on a User Id.

So, I could say Comments.User.FirstName.

Now, when I am building my custom object OComment I am attempting to get the FirstName from the Foreign Key'ed table.

Such as:

public static readonly Func<Comment, OComment> DataToObject = mapper =>
                                                          new OComment
                                                          {
                                                              CommentId = mapper.CommentId,
                                                              CommentSection = mapper.CommentSection,
                                                              DateCreated = mapper.DateCreated,
                                                              Message = mapper.Message,
                                                              UserFullName = mapper.User.FirstName + " " + mapper.User.LastName,
                                                              SectionId = mapper.SectionId,
                                                              UserId = mapper.UserId,
                                                          };

However, when I attempt this I get the following error:

An error occurred while executing the command definition

If i use LINQ to SQL, this works just fine.

Any thoughts on what I am doing wrong, or if there is a better approach to this?

If you need clarification on something, please don't hesitate to ask.

Thanks!