ASP.Net MVC中的模型是什么? [英] What is a model in ASP.Net MVC?

查看:89
本文介绍了ASP.Net MVC中的模型是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个MVC的小网站,但一开始就陷入困境。我对多种事物和方法感到困惑。具体如下: -



1 - 什么是型号,它包含什么?它是仅包含或映射数据库中的表还是其他内容。请在主详细信息场景中提供简单模型或

的示例。我问它是因为我们在实体框架中有导航属性。因此,如果不使用实体,如何显示它。



2 - 我发现实体框架作为连接选项。我想知道这是否是连接的唯一选择。我的意思是我可以使用存储过程(不在实体框架中)。



3 - 如果我正在使用存储过程,我将如何定义模型。



4- 最后,如果我从实体框架开始应该是什么使用:



4a - 数据库优先 - 自动生成代码,难以修改

4b - 代码优先 - Evey时间在模型中有变化时重新生成数据库



所以你可以看到有很多愚蠢的问题但是相信我,这些这是我现在需要的答案。

谢谢。

I am developing a small website in MVC but stuck in very beginning. I am confused about multiple things and approaches. Those are as following:-

1-What is a model and what does it contain? Does it contain or map only tables in the database or it is something else. Please provide an example of a simple model or
in a master detail scenario. I am asking it because we have navigational properties in entity framework. So how this can be shown if not using entity.

2-Every where I find entity framework as connectivity option. I want to know if this is the only option for connectivity.I mean can I use stored procedures(not in entity framework).

3-If I am using stored procedures,how will I define models.

4- Lastly, If I start with entity framework what should be used:

4a-Database first-Auto generated code,hard to modify
4b-Code first- Evey time regenerates db when changes are there in model

So you can see that there are lot of foolish questions but trust me,these are the answers I need at this point of time.
Thank You.

推荐答案

让我更具体地回答你的问题,有点好 - 描述的方式。首先, MVC框架 [ ^ ],不是ASP的一种方法。仅建立.NET应用程序。它是一个软件开发的架构,用于将源代码分为三类,



Let me answer your question more specifically and a bit well-described way. First of all, MVC framework[^], is not an approach of ASP.NET application building only. It is an architecture in software development, used for distributing the source code into three categories,



  1. 模型 - - 我将在下面稍微解释一下,现在它们包含数据。
  2. 查看 - 这是您网站的实际HTML内容
  3. 控制器 - 后端应用程序的逻辑,包括处理程序





现在进入MVC的Model部分。 ASP.NET使用相同的模式进行应用程序开发,模型 - 视图 - 控制器。模型是类,它定义应用程序中的数据结构。它只是定义了您的对象具有哪些成员,以及与您的数据相关的一些其他功能(例如为您的对象获取可枚举;列表)。



其次,您不需要Entity框架来使用ASP.NET MVC中的模型。模型只是定义,它不必来自实体框架,甚至来自数据库。您不应该拥有使用模型的数据库。我将附上我的一篇文章,以支持这一陈述。



您可以使用这些存储过程来执行和返回数据,使用您可以填充模型的数据。您将使用Controller执行Sql命令以从存储过程中获取数据...然后填写模型。只需确保你的模型中有一个成员,它可以保存一个列表。请参阅附件;了解更多。



如果你没有使用Entity框架,那就不要使用它。谁强迫你使用一个?我不会回答这一部分。



这是我的文章,它解释了ASP.NET MVC适合初学者和中间人。它不使用Entity框架,因为ASP.NET开发人员已经很好地解释了Entity框架。这就是为什么我尝试将JSON(不是SQL数据库)用于我的应用程序的数据源。我想这篇文章非常适合你的病情。你应该试一试。它将澄清您的所有概念和混淆。



使用真实世界的例子,为初学者和中级人员理解ASP.NET MVC [ ^ ]



Now coming to the Model part of the MVC. ASP.NET uses the same pattern for application development, Model-view-controller. A model is the class, that defines the structure of data in your application. It simply defines what members your object has, and a few other functions related to your data (such as getting enumerable for your objects; list).

Secondly, you do not need Entity framework to work with Models in ASP.NET MVC. A model is just the definition, it doesn't has to be coming from Entity framework, or a database even. You are not supposed to have a database to use a Model. I will attach an article of mine with this answer to support this statement.

You can use those stored procedures to execute and return the data, using that data you can fill your models. You will be using the Controller to execute the Sql commands to get the data from a stored procedure... And thus then fill in the Model. Just make sure you're having a member inside your model, which can hold a list. Please see the attached article; for more on this.

If you're not using Entity framework, then don't use it. Who's forcing you to use one? I will not answer this part.

This is the article of mine, that explains ASP.NET MVC for beginners and intermediates. It doesn't use Entity framework, because Entity framework has been explained well by the ASP.NET developers. That is why I tried using JSON (not SQL database) for the data source for my application. I guess that article is a perfect for your condition here. You should try it a try. It will clarify all of your concepts and confusions.

Understanding ASP.NET MVC using real world example, for beginners and intermediate[^]


引用:

什么是型号?





型号是映射到表的类。





Model is class that maps to the Table.

Quote:

它包含什么?



它包含所有应用程序逻辑如业务逻辑,验证逻辑和数据访问逻辑。




It contains all application logic like business logic, validation logic, and data access logic.

Quote:

我想知道这是否是唯一的连接选项

I want to know if this is the only option for connectivity





不,它不是唯一的选择。它是最好的选择之一。

为什么最好?

当我开始学习MVC时提出同样的问题。请参阅。

实体框架或MVC的LINQ? [ ^ ]





No it is not the only option .It is the one of the best option.
why it is best?
The same question raised when i start to learn MVC.Refer it.
Entity Framwork or LINQ for MVC ?[^]

引用:

我可以使用存储过程





是的,你可以在MVC中使用存储过程







Yes you can use Stored Procedures in MVC


Quote:

如果我使用存储过程,我将如何定义模型。

If I am using stored procedures,how will I define models.





参考。

HTTP: //www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/async-and-stored-proce dures-with-the-entity-framework-in-an-asp-mvc-application [ ^ ]







Refer it.
http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/async-and-stored-procedures-with-the-entity-framework-in-an-asp-net-mvc-application[^]


引用:

如果我从实体框架开始应该使用什么:

If I start with entity framework what should be used:





请参考

EF代码优先或模型优先或数据库优先? [ ^ ]





我希望能帮到你。



Refer it
EF code first or Model First or DB First?[^]


I hope its help you.


这篇关于ASP.Net MVC中的模型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆