铁轨 + C# - 重用模型

发布于 2024-08-13 00:43:37 字数 87 浏览 11 评论 0原文

我正在开发一个项目,该项目有一个 Rails 网站和一个使用相同数据库和数据模型的 C# GUI。我想分享两个部分之间的(活动)模型。关于这如何可能的任何想法?

I'm working on a project that has a website in Rails and a C# GUI that use the same database and data models. I'd like to share the (active)models between the two parts. Any ideas on how this is possible?

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

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

发布评论

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

评论(3

季末如歌 2024-08-20 00:43:37

IronRuby 正是为此而设计的。

您需要使用 IronRuby 运行 Ruby on Rails(您也可以通过 IIS 执行此操作),然后您可以像调用 Ruby 库一样调用 C# 程序集。

一些帮助您入门的资源:

  • http://IronRuby.net - 包含一些文档的官方网站(不完整,但您会在那里找到一些好的信息)
  • http://www.IronShay.com - 我的博客,其中有几篇关于 IronRuby 的文章。如果您需要更多指导,您也可以通过联系表与我联系
  • http://www.ruby- forum.com/forum/34 - IronRuby 论坛/邮件列表,IronRuby 社区成员和团队成员回答的问题。

IronRuby is exactly for that.

You will need to run Ruby on Rails with IronRuby (you can do that via IIS too) and then you can call your C# assemblies like they were Ruby libraries.

Some resources to get you started:

  • http://IronRuby.net - official site with some documentation (not full but you will find some good info there)
  • http://www.IronShay.com - my blog with several posts about IronRuby. You can also contact me via its contact form if you need more directions
  • http://www.ruby-forum.com/forum/34 - The IronRuby forum/mailing list, questions answered by members of the IronRuby community and the team members as well.
红衣飘飘貌似仙 2024-08-20 00:43:37

简短的回答是,如果不在 C# gui 上重新定义它们,就无法做到这一点。
您可以将控制器公开为 WSDL/SOAP 而不是其余的东西,然后您可以让 Visual Studio 为您生成代理。 C# 在动态方面确实很糟糕,因此您不能只采用 ruby​​ 模型并在 C# 中重用它们,因为它们需要编译。

您当然可以为 Rails 的“宁静”资源编写自己的代理生成工具,但最终您将不得不以某种方式复制模型代码。

就像 shay 所说的那样,您可以使用 IronRuby 来弥补差距,但这取决于您是否想要重用 ActiveRecord 类,或者您是否使用网站作为获取数据的点?
当您想要重用 activerecord 模型时,IronRuby 是与数据库对话的方法(但为了与 C# 良好集成,您必须围绕模型创建强类型包装器,所以我真的不明白这一点) 。

The short answer is you can't without redefining them on the C# gui.
You can expose the controllers as WSDL/SOAP instead of the restful stuff, then you can have visual studio generate the proxies for you. C# is really bad at dynamic stuff so you can't just take the ruby models and reuse them in C# because they need to be compiled.

You can of course write your own proxy generation tool for the "restful" resources of rails but at the end of the day you'll have to duplicate the model code somehow.

Like shay says you can use IronRuby to bridge the gap but it depends do you want to reuse the ActiveRecord classes or are you using the website as your point to get to the data?
When you want to reuse the activerecord models then IronRuby is the way to go to talk to your database (but to get good integration with C# you would have to create strong typed wrappers around the models, so I don't really see the point).

合久必婚 2024-08-20 00:43:37

First thing that comes to mind for me would be to expose RESTful web services from the Rails application, and consume those services in your C# client application. I don't know of a way to avoid duplication if you want POCO's in your C# application - maybe write a CodeSmith or T4 template that reads schema.rb and generates POCO's.

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