Is there a .NET equivalent to Rails Console?

前端 未结 2 775
长发绾君心
长发绾君心 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();
    

提交回复
热议问题