Is there a .NET equivalent to Rails Console?

前端 未结 2 774
长发绾君心
长发绾君心 2021-01-07 22:55

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 LinqPA

相关标签:
2条回答
  • 2021-01-07 23:10

    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();
    
    0 讨论(0)
  • 2021-01-07 23:17

    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.

    0 讨论(0)
提交回复
热议问题