Linq To 实体、MVC、创建视图
我有一个应用程序想要迁移到 ASP.NET MVC。几乎没有什么障碍是我无法清除的。
我正在使用以下组件
- Linq to Entities
- MVC 和 Razor
现在我遇到了三个主要障碍。
- sql 查询非常复杂 - 我想按原样使用它(没有 Linq )
- 如何创建一个视图来显示此查询结果集中的数据
- 该查询涉及跨多个数据库的表的联接(尽管在同一服务器上) - 什么是未来使其成为纯linq的最佳方法。
I have an application that I want to migrate to ASP.NET MVC. There are few stumbling blocks that I am not able to clear.
I am using the following components
- Linq to Entities
- MVC with Razor
Now I have three major hurdles.
- The sql query is quite complex - I want to use it as it is (without Linq )
- How to create a view that will display data from this query's resultset
- the query involves joins on tables across multiple databases (though on the same server ) - what is the best approach to make it pure-linq in future.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己仍在学习实体框架,但希望我的回答能够为您提供一些建议和起点。
如果您有一个复杂的 SQL 查询,并且希望保持原样,那么最好的选择是将其作为存储过程添加到数据库中。然后,您可以使用实体框架添加/调用存储过程。您可以将模型设置为使用存储过程。
使用我在#1中的建议,我建议您简单地构建一个自定义对象来将数据存储在您需要的结构中。在您的控制器中(或者您为数据/业务设置了项目)逻辑),您可以通过使用 EF 调用存储过程来填充对象。然后,您可以创建视图并针对该对象/模型强类型化它,并以所需的任何方式显示它。
至于这个问题,我不确定。不过,我确实进行了快速搜索,希望这篇文章可以帮助您指明方向。 EF4跨数据库关系
I'm still learning the Entity Framework myself, but hopefully my answer will help you out a little with some advice and starting points.
If you have a complex sql query that you want to leave intact as is, your best bet is to add it as a Stored Procedure in your Database. You could then add/call the Stored Procedure using the Entity Framework. You can set up the model to use a stored procedure.
Using my suggestion in #1, I'd recommend you simply build a custom object to store the data in the structure you need it to be in. In your controller (or however you have your project set up for data/business logic) you can populate the object by using EF to call the Stored Procedure. You could then create your view and strongly type it against that object/model and display it in whatever manner it's needed in.
As for this question, I am not sure. However, I did do a quick search and hopefully this thread may help point you in a direction. EF4 cross database relationships