意见:使用 .net mvc 检索/列出数据的最佳方法
我是 MVC 框架的新手,我想知道您认为检索数据并将其列在页面上的理想方式是什么。具体来说,我指的是报告类型页面中使用的数据,而不是电影、书籍或其他明确“对象”的列表。
大多数在线示例似乎建议使用 ADO.net 实体数据模型和实体数据模型。 LINQ 由向导使用数据库模式自动构建 - 这对于电影/书籍之类的东西来说似乎很棒,但对于报告所需的随机数据似乎并不那么直观“正确”。
这可能是一个太模糊/太宽泛的问题,但任何帮助将不胜感激。
更新: 更具体地说,我基本上需要从 Sql 服务器视图中获取一组行并将它们显示在页面上。其中一些只是在列表中,一些在图表中(计划使用 .net 图表控件)。我意识到我正在做的事情非常简单,我只是不确定使用 MVC 框架执行此操作的最佳方法是什么。希望能澄清一点...
I'm new with the MVC framework and I was wondering what you think is the ideal way to retrieve data and list it on a page. Specifically, I'm referring to data used in report type pages, not lists of movies, books, or other clear 'objects'.
Most online samples seem to suggest using ADO.net Entity Data Models & LINQ which are automatically built by the wizard using the DB schema - and that seems great for things like movies/books, but doesn't seem so intuitively 'correct' for random data needed for a report.
This may be too vague/broad of a question, but any help would be appreciated.
Update:
To be more specific, I basically need to take a set of rows from a Sql server view and display them on a page. Some of it just in a list, and some in graphs (planning to use the .net charting control). I realize what I'm doing is very simple, I'm just not sure what the best way of doing it using the MVC framework is. Hope that clears it up a bit...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需以最佳方式将数据分组到某个容器对象中,然后使用该容器对象作为视图的模型即可。您的模型可以轻松挑选和选择 ORM 生成的对象的各个方面来填充自身。
每个报表页面都可以继承一个唯一的模型对象,因此每个报表都可以了解它需要的不同数据。
(注意:有时这称为“ViewModel”,因为它是视图所需的不同模型部分的合并,但它并不完全是域建模中的真实对象。但是,更严格地说,ViewModel 还有其他当您在 MVVM 风格设计中使用它时的含义。)
Just group the data the best way you can into some container object, and use that container object as the Model for your View. Your model can easily pick and choose aspects of the objects that are generated by your ORM to populate itself with.
Each report page can inherit from a unique Model object, so each report can know about the different data it needs.
(Note: Sometimes this is called a "ViewModel", since it's an amalgamation of the different model pieces that you need for your view, but it isn't exactly a real object in your domain modelling. However, more strictly a ViewModel has other connotations when you're using it in MVVM style designs.)
我不确定在不知道具体要求的情况下是否可以回答这个问题。如果您正在寻找一些东西来获取任何随机数据,那么您会遇到一个非常独特的问题,因为没有 C# ORM 映射器(Linq2Sql、NHibernate、Entity Framework、SubSonic)只会为您自动更正内容。
问题是创建映射到数据的 C# 类的常见做法。您不能在不重新编译的情况下更改它们。我猜想动态对象可以工作,但是没有一个动态 ORM 映射系统可以与它们一起工作。
很确定您正在考虑使用 Ado.net 库来滚动自己的工具来处理动态表和数据源。
I'm not sure if this question can be answered without knowing specific requirements. If your looking for something to take any random data then you have a really unique issue because no C# ORM mapper ( Linq2Sql, NHibernate, Entity Framework, SubSonic ) will just autocorrect things for you.
The issue is the common practice of creating C# classes which map to your data. You can't just change them without a recompile. I guess dynamic objects would work but there isn't a dynamic ORM mapping system that will work with them.
Pretty sure your looking at rolling your own tooling with the Ado.net libaries to handle dynamic tables and data sources.
关键词“报告”让我想起强烈的疑问。为此使用存储过程。不然就EF一路走!呜呜
Keyword "reporting" makes me think of intense queries. Use stored procs for that. Otherwise EF all the way! woooo