Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
C#
public BoardPost GetPostByID(Int64 PostID)
    {
           BoardPost result = null;
           using(FisharooDataContext dc = _conn.GetContext())
          {
               BoardPost post = dc.BoardPosts.Include("Account").Where(p =>  
                   p.PostID == PostID).FirstOrDefault();
               result = post;
               result.Account = post.Account;
          }
           return result;
  }


I am failing to overcome the error at line no 6 probably due to wrong coding at line no 4 or due to some missing assembly references. Dear friends, please help me out. Thank you.
Posted
Updated 22-Feb-12 7:19am
v2
Comments
Martin Arapovic 22-Feb-12 12:15pm    
Please post your exception details...
Brajabas 22-Feb-12 23:08pm    
Sorry, I am too late to respond you. The error comes during the coding itself. when I type "result.Account=post.Account", the "Account" is not accepted by the statement. Am I wrong in the coding:
BoardPost post = dc.BoardPosts.Include("Account").Where(p =>
p.PostID == PostID).FirstOrDefault();"
or in somewhere else?
Martin Arapovic 23-Feb-12 2:21am    
Hi, I don't know your data model, but "Account" must be property on your BoardPost and all must work.
Actually, as I can see you can remove "result.Account = post.Account;" line because your method is returning BoardPost object and you included "Account" in your query and "Account" will be already loaded with BoardPost.
Brajabas 23-Feb-12 4:47am    
I don't have experience in high level coding with entity framework. Grateful to you for this concept which is new to me. Please suggest some articles, whenever you get time, on this issue so that I could get a broad vision on this concept. Thank you.
Martin Arapovic 23-Feb-12 7:42am    
Hi,

You can read this book (http://www.amazon.com/Programming-Entity-Framework-Building-Centric/dp/0596807260) and look examples on this site (http://learnentityframework.com/LearnEntityFramework/tutorials/).
Also download LinqPad (http://www.linqpad.net/) for easier and faster testing...
And there is google also if you need more information regarding something specific... :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900