Posts from March 2010

Mar
8
2010

Entity Framework in Mednium Trust



Posted in ASP.NET

ASP.NET and medium trust typically don’t get along well once you start using third party libraries. It really should, however, be easier to get the Entity Framework working on medium trust, and this had me baffled for a few hours trying to split the EDMX file and other fruitless solutions.

To get this working I needed to:

  1. Move the EDMX to a separate assembly.
  2. Set the EDMX metadata artifact processing to ‘Embed in output assembly’.
  3. Add a reference in the site.
  4. Change the connection string to
    <add name="ShopEntities" connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=servername;Initial Catalog=dbname;User Id=username;Password=P@55word;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

Which every guide claimed would work. There’s one more step if you have custom partial entity classes (in App_Code). If so, these also need to be moved to your output assembly, as you can’t split partial classes across assemblies. Lastly, change the namespace in your partial classes to the same as your output assembly, and everything should work.