EF Entities - Does not exist in current context

Dec 10, 2011 at 12:16 PM
Edited Dec 10, 2011 at 3:13 PM

Hi All, Thanks for a great library by the way.

I have an issue of parsing EF Entities. I apologize for the VB code, this client requires it.

The code is below. My issue is that I get the "Unable to compile template. The name 'mm' does not exist in the current context" error.

I am passing in an Iso Entity which contains about 40 MerchantMaster entities in the MerchantMaster collection. I have attempted to declare the variable mm in the header to no avail. I'm new to razor so I'm hoping it's just bad syntax, or do I have to import all the types I am going to use. Also, I haven't changed anything from vanilla razorengine so the template code is c#. Thanks in advance.

Paul

 

Private Sub OutputSingleEF()
        CompilerServiceBuilder.SetCompilerServiceFactory(New DefaultCompilerServiceFactory())
        Using entCtx As PCISiteEntities = New PCISiteEntities()
            Dim query = entCtx.Iso.Include("MerchantMaster")
            Dim template As String = " @{ " & vbCrLf & _
                " " & vbCrLf & _
                "}" & vbCrLf & _
                "<h1>IsoName: @Model.Name</h1>" & vbCrLf & "   DBA: @mm.DBA " & vbCrLf & _
                "   @foreach(var mm in Model.MerchantMaster){ " & vbCrLf & _
                "       @mm.DBA<br /> " & vbCrLf & _
                "   }"

            Dim i As Iso = (From s In query Where s.ID = 1 Select s).FirstOrDefault()
            Using service = New TemplateService()

                Dim result = service.Parse(template, i)

                litOutput.Text = result
            End Using
        End Using
    End Sub

 

Dec 10, 2011 at 12:39 PM

It's amazing. I spent a great deal of time looking at this code and trying to debug it.

I started a thread, only after hours of googling for answers (I thought I was not loading the correct types).

Then right after I post, I see my problem right in my own post. I am attempting to use the mm var before it's declared LOL.

This template works just fine:

Dim template As String = " @{ " & vbCrLf & _
                " " & vbCrLf & _
                "}" & vbCrLf & _
                "<h1>IsoName: @Model.Name</h1>" & vbCrLf & vbCrLf & _
                "   @foreach(var mm in Model.MerchantMaster){ " & vbCrLf & _
                "       @mm.DBA<br /> " & vbCrLf & _
                "   }"

Thanks again for the great class library.

Coordinator
Dec 16, 2011 at 9:16 AM

Hi,

Glad you resolved your issue. As you are a VB developer, would you consider testing out v3? (https://github.com/Antaris/RazorEngine/tree/release-3.0), which is available currently on Nuget as v3.0.5beta (Install-Package RazorEngine)

Feedback would be very welcome.

Oh, also could you report any issues to our new home at GitHub? (https://github.com/Antaris/RazorEngine)

Kind Regards,
Matt 

Dec 16, 2011 at 12:45 PM
Since you spent the time to write a great library which has a possibly small niche usage, I would love to help you any way I can. The only thing is that the client requires the website be in VB.net, but allows me to write my libraries in c#. So I have written a wrapper in c# which does the EF4 queries (so I can use anonymous methods, which I find hard to believe is completely left out of VB) and constructs emails.

I know what you are probably looking for is how nicely RazorEngine plays with VB and I may not be able to help much in that arena. But I will do what I can. I did some preliminary tests using VB and everything worked fine.

Sincerely,

Paul Perrick

On Fri, Dec 16, 2011 at 7:16 PM, AntarisZX <notifications@codeplex.com> wrote:

From: AntarisZX

Hi,

Glad you resolved your issue. As you are a VB developer, would you consider testing out v3? (https://github.com/Antaris/RazorEngine/tree/release-3.0), which is available currently on Nuget as v3.0.5beta (Install-Package RazorEngine)

Feedback would be very welcome.

Oh, also could you report any issues to our new home at GitHub? (https://github.com/Antaris/RazorEngine)

Kind Regards,
Matt

Read the full discussion online.

To add a post to this discussion, reply to this email (razorengine@discussions.codeplex.com)

To start a new discussion for this project, email razorengine@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com