LinqPad - EntityFramework 4.3.1 - MissingMethodException - Sql Compact - .net-4.0

I have my POCO model is seperate dll than my asp.net mvc 3 website.
I created new connection in LinqPad Beta: v4.41.01 selected option for Poco, provided path to custom dll, Chose DbContext, Chose via parameterless constructor.
This did not work, as I am using SqlServer Compact.
Then I created dummy.config file as follows:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
<connectionStrings>
<add name="ModelContext"
connectionString="data source=database.sdf"
providerName="system.data.sqlserverce.4.0" />
</connectionStrings>
</configuration>
With this, Test on connection is shown successful. Even, tree on left is also populated. But when I run any query, it throws exception as follows:
Method not found: 'System.Data.Entity.DbSet`1 InventoryModelContext.get_xxx()'.
EDIT: Also, note that this seems to be compilation error!
Any solution or workaround? Am I missing something?
Thanks in advance.

I had this problem as well, it started without any apparent reason - did not change anything in my environment.
I am using EF4.2 Poco, LINQPad 4.42.01
To resolve I started running LINQPad as Administartor, it solved it. I am not sure what has changed that made it break, I have not used LINQPad for a while, so maybe it was some auto-update of LINQPad or something like that.
Update: After reinstalling, for some reason the Administartor trick was not working, a new method I found is query first without specifying a database (at the top right, it says <None>), then i get an error that what I am querying for does not exists in this context, and then I set the database to the correct context, and it works.
Still not sure what is actually causing it.

Related

Could not load file or assembly 'Microsoft.AspNet.Web.Optimization.WebForms' or one of its dependencies. The system cannot find the file specified

I can't find anything to resolve this and have tried multiple things.
Task: I am trying to add bundles to an old existing web project. I have added everything I need I believe as I have done the same in a new project and it works.
<webopt:BundleReference runat="server" Path="~/bundles/masterstyle" />
This seems to be where the issue has started with this line above. I installed via nuget the web optimization webforms package which fixed the squiggly line under webopt. However, now, I am getting 2 issues.
BundleReference has a squiggly line saying "Element
'BundleReference' is not a known element/ This can occur if there is
a complication error in the Web site, or the web.config file is
missing".
It also can't seem to find the package I have just installed which
is "Could not load file or assembly
'Microsoft.AspNet.Web.Optimization.WebForms' or one of its
dependencies. The system cannot find the file specified".
If anyone can help resolve this, it would be greatly appreciated. Been stuck on it for 4 hours now.
Here is the likely relevant stuff in my web.config file:
<pages>
<namespaces>
<add namespace="System.Web.Optimization"/>
</namespaces>
<tagMapping>
<add tagType="System.Web.UI.HtmlControls.HtmlForm" mappedTagType="we3.Site.Form" />
</tagMapping>
<controls>
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt"/>
</controls>
</pages>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
Install it from nugget: https://www.nuget.org/packages/Microsoft.AspNet.Web.Optimization.WebForms/
Install-Package Microsoft.AspNet.Web.Optimization.WebForms
Or you can manually download it from: https://www.nuget.org/api/v2/package/Microsoft.AspNet.Web.Optimization.WebForms/1.1.3
and add it as reference to your project (unzip first the .nupkg file)
Installing the package Microsoft.AspNet.Web.Optimization is what resolved this for me.
Install-Package Microsoft.AspNet.Web.Optimization

"Ado.Net Entity Data Model" template with VS2010, EF6 and SQLite EF6 provider?

As I got a pitch for future project specifying XP compatibility I'm trying to test combination of VS 2010 (WinXP SP3), .Net 4.0.3 (later WPF for UI), Entity Framework 6 (as I found out it should be compatible with .Net 4) and SQLite (System.Data.SQLite / .EF6).
I installed "EntityFramework" and "System.Data.SQLite EF6" packages from NuGet.
("System.Data.SQLite EF6" in turn installed System.Data.SQLite, System.Data.SQLite.EF6 and SQLite.Interop.dll)
Now trying to use "Ado.Net Entity Data Model" template, which I guessed from older tutorials would be next step I get to new connection dialog and no SQLite provider is listed there to select.
I checked my App.config and SQLite data providers are listed there. (If correctly I can't tell)
Looking like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0.3,Profile=Client" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<remove invariant="System.Data.SQLite.EF6" />
<add name="SQLite Data Provider (Entity Framework 6)"
invariant="System.Data.SQLite.EF6"
description=".Net Framework Data Provider for SQLite (Entity Framework 6)"
type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
<add name="SQLite Data Provider"
invariant="System.Data.SQLite"
description=".Net Framework Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
</configuration>
The app (empty console app) compiles without errors and runs (doing of course nothing).
I am pretty green with EF + SQLite so can you please advice ?
Am I completely on a wrong track with something ?
So after another several hours of desperate googling I found a hint in an old tutorial about Visual Studio Design Time Component(s).
Apparently I was missing the Design Time Components and also System.Data.SQLite libs installed in GAC, without which VS2010 wizards don't 'see' the SQLite provider.
So despite reading in numerous official places that Setup install package is not a recommended method of getting SQLite libs into the project, it is actually the only way of making VS (2010, 12, ?13?) tools work with it.
Istalled one of "setup packages" from http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki . In my case "Setups for 32-bit Windows (.NET Framework 4.0)".
The Template now offers SQLite as data provider.

Having trouble with LinqPad Adding a Connection to Entity Framework

I am new to Entity Framework and Linq to Entities and I want to try LinqPad but I can't figure out how to make a connection to the edmx model I have created.
I have an MVC project and I added an ADO.Net Entity Data Model against a SQL Sever database ( a Development server, not one on my local machine) Did a Build.Right click in my designer surface and Add Code Generation Item. That has given me two .tt folders, one for my dbContext class, one with all my classes.
Open LinqPad click on Add Connection. Point to the .dll file in my solutions bin folder, then in the Full Type Name of dbContext I choose the entity I created. Now is whee I am having trouble making this work. I point to the solution web.config file and when I click the Test button I get an error saying "Could not load file or assembly 'Entity Framework version=..." & "The system cannot find the file specified. (C:\users..\web.config line 9" Any ideas?
I took configSections away from config file and connection works.
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
I've had this exact problem with LinqPad 4.42.01. My project is a web project using an EF5 data assembly. I ended up creating a linqPad.config file (below) in the web projectMy and it works great.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<remove name="MySqlServer"/>
<add name="MySqlServer" connectionString="Data Source=mydb;Initial Catalog=mycat;User ID=iamuser;Password=soopersekret;Trusted_Connection=False" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>

Migrations (Entity Framework 4.3) - script doesn't get executed

The scripts are generated correctly, i use multiple layers so the following commands are run into the Package Manager Console
Eg. When i added Email column to the table : "Owner"
Add-Migration AddEmailToOwner -StartupProjectName "FacturatieMVCv2.Data" -Verbose
--> Result:
Using NuGet project 'FacturatieMVCv2.Data'.
Target database is: 'FacturatieMVCv2.Data.Website.MyResellerContext' (DataSource: V-File \SQLEXPRESS, Provider: System.Data.SqlClient, Origin: Convention).
Next command i use is:
Update-Database -StartupProjectName "FacturatieMVCv2.Data" -Verbose
--> Result:
Using NuGet project 'FacturatieMVCv2.Data'.
Target database is: 'FacturatieMVCv2.Data.Website.MyResellerContext' (DataSource: V-FILE\SQLEXPRESS, Provider: System.Data.SqlClient, Origin: Convention).
Applying explicit migrations: [201203080906140_AddDamnToOwner].
Applying explicit migration: 201203080906140_AddDamnToOwner.
ALTER TABLE [Owners] ADD [Damn] [nvarchar](max)
[Inserting migration history record]
My connectionstring in the App.Config is :
<parameter value="Server=V-FILE\SQLEXPRESS;Persist Security Info=True;Initial Catalog=ProductionReseller;uid=sa;password=n*****3;" />
Although i specified the Initial catalog, it is targetting the wrong catalog. It's created / updated the database table named: FacturatieMVCv2.Data.Website.MyResellerContext .
Following is my app.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<!--<parameter value="Data Source=.\SQLEXPRESS; Integrated Security=True; MultipleActiveResultSets=True" />-->
<parameter value="Server=V-FILE02\SQLEXPRESS;Persist Security Info=True;Initial Catalog=ProductionReseller;uid=sa;password=12345678;" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
</configuration>
In short, the Update-Database command, updated the wrong database.
Using the following command:
Update-Database -StartupProjectName "FacturatieMVCv2.Data" -Verbose -ConnectionString "Server=V-FILE\SQLEXPRESS;Persist Security Info=True;Initial Catalog=ProductionReseller;uid=mydbuser;password=mydbpass;" -ConnectionProviderName "System.Data.SqlClient"
Fixed my problem.
SqlConnectionFactory adds the Initial Catalog to the value you provide. If you want to use a specific connection string for a context, you should add an entry in the connectionStrings section instead. E.g.
<connectionStrings>
<add name="MyResellerContext" connectionString="Server=V-FILE\SQLEXPRESS;Persist Security Info=True;Initial Catalog=ProductionReseller;uid=sa;password=12345678;" providerName="System.Data.SqlClient" />
</connectionStrings>
We store config variables in build configs to switch between these and ran into this issue; the solution was to Clean then explicitly Build.
To expand on that:
Our Db class (the one that inherits DbContext) has a Constructor like:
public Db()
#if AltDb
: base("AltDb")
#else
: base("Db")
#endif
{
}
So if the AltDb build var is defined, it's going to use the ConnectionString named AltDb; otherwise it uses the one named Db. In our Project configs, we have one named AltDb and all it does is define the AltDb build variable.
So we have those 2 connection strings defined in Web.Config:
<connectionStrings>
<add name="Db" connectionString="Initial Catalog=MyProj;Data Source=.\SQLEXPRESS...
<add name="AltDb" connectionString="Initial Catalog=Staging;Data Source...
So, when we want to update the alternate db, we SHOULD be able to just switch build configs and run update-database. This has worked in every project for years, but today it just wouldn't.
When I ran a Clean, then made sure this build config was selected and the startup Project was selected, and explicitly Built, magically it was solved - even though EF appears to build everything every time you run update-database.
I have no explanation as to why this would occur, but that's the cause and solution for us.

NServiceBus persisting subscriptions in Pub/Sub sample

I want to figure out how I to set up the Pub/Sub sample from NServiceBus to work in the case of publisher malfunction.
When I start the samples and accidentaly close the Subscribers, if I restart everything works fine.
If however I kill the publisher and the subscriptions continue to work, if I restart the publisher, then it doesn't seem to know it has subscribers and doesn't post any messages.
I added the config entry
<MsmqSubscriptionStorageConfig Queue="subscriptions"/>
but it seems to not function... I miss something. I googled about MsmqSubscriptionStorageConfig and DbSubscriptionStorageConfig but i didn't find a solution.
Could someone point me in the right direction ?
I found that a couple additional steps are required in order to get this working with the Pub/Sub sample under .Net 4.0, using a SQLite subscription storage system.
Combining the previous suggestions with the new ones, here are the required changes, all of which apply to the MyPublisher project.
Add a reference to System.Data.SQLite. Be sure to choose the version that matches your desired architecture (x86/x64). These items can be found in the 'binaries' folder.
In the App.config file, add the following as a new configSection element:
<section name="DBSubscriptionStorageConfig"
type="NServiceBus.Config.DBSubscriptionStorageConfig, NServiceBus.Core" />
In the App.config file add, the following as a new configuration element:
<DBSubscriptionStorageConfig>
<NHibernateProperties>
<add Key="connection.provider"
Value="NHibernate.Connection.DriverConnectionProvider"/>
<add Key="connection.driver_class"
Value="NHibernate.Driver.SQLite20Driver"/>
<add Key="connection.connection_string"
Value="Data Source=.\Subscriptions.sqlite;Version=3;New=True;"/>
<add Key="dialect"
Value="NHibernate.Dialect.SQLiteDialect"/>
</NHibernateProperties>
</DBSubscriptionStorageConfig>
Add this chunk of XML to the configuration section of the NServiceBus.Host.exe.config file:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
You need to change the profile of the publisher to production.
See http://docs.particular.net/nservicebus/hosting/nservicebus-host/profiles
For debugging this way, go to the properties of the publisher project, into the Debug tab, and put in NServiceBus.Production in the Command line arguments of the Start Options section.