Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Clever Code
  4. local variables in EF Linq query

local variables in EF Linq query

Scheduled Pinned Locked Moved Clever Code
5 Posts 2 Posters 12 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Not Active
    wrote on last edited by
    #1

    I ran into this while trying to use Entity Framework in a WSS application.

    var states = context.State.Where(c => c.Country.ID == countryID).ToList();

    When binding the resulting query to a dropdownlist you get a Javascript error System.Runtime.CompilerServices.StrongBox`1..ctor(System.__Canon). However, this doesn't get the error

    var states = context.State.Where(c => c.Country.ID == 2).ToList();

    The work-around for this, as the link below points out, is to use a public variable in a public class rather than a local variable. http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/thread/0dc87db4-c145-456b-a19f-eebc16c09efb/[^]


    only two letters away from being an asset

    J N 2 Replies Last reply
    0
    • N Not Active

      I ran into this while trying to use Entity Framework in a WSS application.

      var states = context.State.Where(c => c.Country.ID == countryID).ToList();

      When binding the resulting query to a dropdownlist you get a Javascript error System.Runtime.CompilerServices.StrongBox`1..ctor(System.__Canon). However, this doesn't get the error

      var states = context.State.Where(c => c.Country.ID == 2).ToList();

      The work-around for this, as the link below points out, is to use a public variable in a public class rather than a local variable. http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/thread/0dc87db4-c145-456b-a19f-eebc16c09efb/[^]


      only two letters away from being an asset

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      That's one hack of a work around. Yuck.

      Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango

      N 1 Reply Last reply
      0
      • J Judah Gabriel Himango

        That's one hack of a work around. Yuck.

        Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango

        N Offline
        N Offline
        Not Active
        wrote on last edited by
        #3

        I was literally just on a call with Microsoft discussing this and so far they have no better solution.


        only two letters away from being an asset

        J 1 Reply Last reply
        0
        • N Not Active

          I was literally just on a call with Microsoft discussing this and so far they have no better solution.


          only two letters away from being an asset

          J Offline
          J Offline
          Judah Gabriel Himango
          wrote on last edited by
          #4

          Wow. What a shame. Such an ugly hack.

          Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango

          1 Reply Last reply
          0
          • N Not Active

            I ran into this while trying to use Entity Framework in a WSS application.

            var states = context.State.Where(c => c.Country.ID == countryID).ToList();

            When binding the resulting query to a dropdownlist you get a Javascript error System.Runtime.CompilerServices.StrongBox`1..ctor(System.__Canon). However, this doesn't get the error

            var states = context.State.Where(c => c.Country.ID == 2).ToList();

            The work-around for this, as the link below points out, is to use a public variable in a public class rather than a local variable. http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/thread/0dc87db4-c145-456b-a19f-eebc16c09efb/[^]


            only two letters away from being an asset

            N Offline
            N Offline
            Not Active
            wrote on last edited by
            #5

            From Microsoft support: This is happening because SharePoint uses its own version of “Medium” trust, which does not enable reflection. The ASP.NET medium trust configuration was changed when Visual Studio 2008 was released to allow reflection in very specific cases. LINQ to SQL and Entity Framework need this permission in order to query in the way that you want. To make this work in your specific scenario, you can add the following in your SharePoint wss_mediumtrust.config file (on my machine it is located in %CommonProgramFiles%\Microsoft Shared\Web Server Extensions\12\config\wss_mediumtrust.config). The only difference is that this will enable code to do reflection to discover non-public members in assemblies that are in the same trust level (i.e. SharePoint Medium trust). (This is a simplification; it’s known as RestrictedMemberAccess, and there is more info here[^].) wss_mediumtrust.config Add the following in the SecurityClasses

            <SecurityClass Name="ReflectionPermission" Description="System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

            Then add the following in PermissionSet

            <IPermission class="ReflectionPermission" version="1" Flags="RestrictedMemberAccess"/>


            only two letters away from being an asset

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups