17

Rails Console is so useful for direct sanity-checking of your model. Is there an ASP.NET MVC equivalent?

Is it possible to mimic Rails Console behaviour using LinqPAD?

Lloyd
  • 8,204
  • 2
  • 38
  • 53

2 Answers2

4

Not really, since you're not inside the running application in the same way as with the Rails Console. - As Lloyd shows in his answer, it seems to be very much possible. Still seems that it's easier to use the Immediate Window if it is sufficient for what you are trying to achieve.

LINQPad is great anyway and I use it similarly to how I use the Ruby Interactive Ruby Shell (IRB).

The Immediate Window in the Visual Studio debugger can get you close to the same experience as the Rails Console gives. I hope that C# 5.0 will get us even closer because as of now you can't use lambda expressions and such.

Jonas Elfström
  • 30,834
  • 6
  • 70
  • 106
3

awesome - I discovered LinqPAD 4.38.03 (latest beta version) works perfectly well as a Rails Console substitute!

My ASP.NET MVC3 project is based on Entity Framework 4.2 (using the "database first" approach) which Linqpad integrates nicely with. I am able to reference my assembly as a connection and query the model, controller, repositories etc. interactively, just like in Rails Console!

These were my steps

  1. In the Connection manager (to the left) click "Add connection"
  2. click the radio labelled "use a typed data context from your own assembly"
  3. click "Entity Framework dbContext POCO (4.1/4.2)", then "next"
  4. use "browse" to locate the "path to custom assembly" (in your project)
  5. click "choose" to select the dbContext class from your assembly
  6. click "choose" to locate your project config file in "path to application config file"
  7. type an optional connection name, click "next"

Finally, in your query window select your new assembly connection as the "Database" and that's it! You can now work with your assembly interactively.

For example, to inspect and test a controller: (first, in Query Properties, add a reference to System.Web.Mvc)

var controller = MyProject.Controllers.CustomerController();
controller.Index().Dump();

to "post" some data

var customer = new Customer() {name = "Brian"};
controller.Create(customer);

to see your new Customer in the database

Customers.Dump();

or if you have a repository

var repo = new Repository();
repo.GetCustomers().Dump();
Lloyd
  • 8,204
  • 2
  • 38
  • 53