Click here to Skip to main content
15,922,325 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public dynamic GetPosts()
       {

           var ret = (from post in db.Posts.ToList()
                     orderby post.PostedDate descending
                     select new
                     {
                         Message = post.Message,
                         PostedBy = post.PostedBy,
                         PostedByName = post.UserProfile.UserName,
                         PostedByAvatar =imgFolder +(String.IsNullOrEmpty(post.UserProfile.AvatarExt) ? defaultAvatar : post.PostedBy + "." + post.UserProfile.AvatarExt),
                         PostedDate = post.PostedDate,
                         PostId = post.PostId,
                         PostComments = from comment in post.PostComments.ToList()
                                        orderby comment.CommentedDate
                                        select new
                                        {
                                            CommentedBy = comment.CommentedBy,
                                            CommentedByName = comment.UserProfile.UserName,
                                            CommentedByAvatar = imgFolder +(String.IsNullOrEmpty(comment.UserProfile.AvatarExt) ? defaultAvatar :  comment.CommentedBy + "." + comment.UserProfile.AvatarExt),
                                            CommentedDate = comment.CommentedDate,
                                            CommentId = comment.CommentId,
                                            Message = comment.Message,
                                            PostId = comment.PostId

                                        }
                     }).AsEnumerable();
           return ret;
       }

I stuck with the dynamic type don't know how to convert it into vb
Here is my VB Code:
VB
Public Function GetPosts() As IEnumerable(Of Post)



        Dim ret = (From post In db.Posts.ToList() Order By post.PostedDate Descending Select New With { _
                Key .Message = post.Message, _
                Key .PostedBy = post.PostedBy, _
                Key .PostedByName = post.UserProfile.UserName, _
                Key .PostedByAvatar = imgFolder & Convert.ToString((If([String].IsNullOrEmpty(post.UserProfile.AvatarExt), defaultAvatar, post.PostedBy + "." + post.UserProfile.AvatarExt))), _
                Key .PostedDate = post.PostedDate, _
                Key .PostId = post.PostId, _
                Key .PostComments = From comment In post.PostComments.ToList() Order By comment.CommentedDate Select New With { _
                    Key .CommentedBy = comment.CommentedBy, _
                    Key .CommentedByName = comment.UserProfile.UserName, _
                    Key .CommentedByAvatar = imgFolder & Convert.ToString((If([String].IsNullOrEmpty(comment.UserProfile.AvatarExt), defaultAvatar, comment.CommentedBy + "." + comment.UserProfile.AvatarExt))), _
                    Key .CommentedDate = comment.CommentedDate, _
                    Key .CommentId = comment.CommentId, _
                    Key .Message = comment.Message, _
                    Key .PostId = comment.PostId _
                } _
            }).AsEnumerable()
        Return ret

    End Function
Posted
Comments
Sergey Alexandrovich Kryukov 5-May-15 21:27pm    
First of all: why using dynamic?
—SA

1 solution

You can do automatic translation. First of all, consider using open-source ILSpy. Please see my past answer:
Code Interpretation, C# to VB.NET[^].

—SA
 
Share this answer
 

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