是否有与 Rails Console 等效的 .NET 版本?

发布于 2025-01-08 01:25:48 字数 97 浏览 0 评论 0原文

Rails Console 对于直接检查模型的健全性非常有用。是否有 ASP.NET MVC 等效项?

是否可以使用 LinqPAD 模拟 Rails 控制台行为?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白云不回头 2025-01-15 01:25:48

并非如此,因为您不像使用 Rails Console 那样进入正在运行的应用程序。 - 正如 Lloyd 在他的回答中所示,这似乎很有可能。如果立即窗口足以满足您想要实现的目标,那么使用立即窗口似乎仍然更容易。

无论如何,LINQPad 都很棒,我使用它的方式与使用 Ruby Interactive Ruby Shell (IRB) 的方式类似。

Visual Studio 中的立即窗口调试器可以让您接近与 Rails Console 提供的体验相同。我希望 C# 5.0 能让我们更接近,因为现在您 不能使用 lambda 表达式 等。

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.

碍人泪离人颜 2025-01-15 01:25:48

太棒了 - 我发现 LinqPAD 4.38.03(最新测试版)作为 Rails Console 的替代品运行得非常好!

我的 ASP.NET MVC3 项目基于 Entity Framework 4.2(使用“数据库优先”方法),Linqpad 与它很好地集成。我能够将我的程序集作为连接引用,并以交互方式查询模型、控制器、存储库等,就像在 Rails Console 中一样!

这些是我的步骤

  1. 在连接管理器(左侧)中单击“添加连接”,
  2. 单击标有“使用您自己的程序集中的类型化数据上下文”的单选按钮,
  3. 单击“Entity Framework dbContext POCO (4.1/4.2)”,然后单击“下一步”
  4. 使用“浏览”找到“自定义程序集的路径”(在您的项目中)
  5. 单击“选择”从程序集中选择 dbContext 类
  6. 单击“选择”在“应用程序配置文件的路径”中找到您的项目配置文件,然后
  7. 键入选修的连接名称,单击“下一步”

最后,在查询窗口中选择新的程序集连接作为“数据库”,就是这样!您现在可以交互地使用您的程序集。

例如,要检查和测试控制器:(首先,在查询属性中,添加对 System.Web.Mvc 的引用)

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

“发布”一些数据

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

以查看数据库中的新客户

Customers.Dump();

,或者如果你有一个存储库

var repo = new Repository();
repo.GetCustomers().Dump();

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文