0

I have an asp.net mvc 5 website using EF, LocalDB and Code First Migrations. Requirements have now dictated that I need a need to add a console application into the mix to do some scheduled work. However this console app must call into the database functionality exposed in the web application. Also of note is that we are using LocalDB for development, but will switch to a 'proper' remote DB for production.

As such I have created a new console application within the project and added a reference to the web application so that I can call its repository functions. I know this probably isn't the best way to handle things.

For whatever reason though, when calling Save Changes on the database context from within the console application, nothing is saved to the LocalDB database. The Save function returns a number indicating that a number of rows were inserted.

I get the feeling I am making a schoolboy error somewhere. What could it be?

Sergio
  • 9,761
  • 16
  • 60
  • 88

2 Answers2

0

i`v used this in the past:

<add name="DefaultConnection" 
connectionString="Server=(localdb)\v11.0;Database=WebPortalDb" providerName="System.Data.SqlClient"/> 
SHM
  • 1,896
  • 19
  • 48
0

If you want to use the functionality/database from one Project to another project then use the following::

1) Include the 'ConsoleProjectName.dll' file into your 'MVC' project's reference

2) Use that Dll into the namespace of your file.

(eg. using System.Data.Entity) in the same way you have to use the DLL into your namespace.

3) make an object of the 'console' application's class and use the methods & other properties defined in that class.

May be this much information will be helpful for you. This we are doing for n-tired architecture, where there are different layers (i.e. projects) in a solution to be linked with each other.

Rahul
  • 2,309
  • 6
  • 33
  • 60