ASP。Net MVC博客内容存储

时间:2022-06-01 21:25:50

I'm creating a blog in asp.net mvc for learning purpose so please no answers telling me i should use an open source blogengine. I need to understand how is the blog content going to work. So i have a table called "Blog" with a column called "Content". The "Content" will hold the blog i.e. text and images etc. Now i have the following questions:

我在asp.net mvc中创建了一个博客用于学习,所以请不要回答我应该使用一个开源的博客引擎。我需要了解博客内容是如何工作的。因此,我有一个名为“Blog”的表格,其中有一个名为“Content”的列。“内容”将包含博客,文字和图片等。现在我有以下问题:

  1. What should be the datatype of content.
  2. 内容的数据类型应该是什么?
  3. Is this the correct way of doing it i.e. saving the blog in a record.
  4. 这是正确的做法吗?比如把博客保存在一个记录里。
  5. What are the contants of this blog i.e. is it html with rich text and image urls and how does it actually work, i.e. where are these image urls be pointing to and how will my application render it.
  6. 这个博客的内容是什么?例如,它是html,有丰富的文本和图像url吗?它是如何工作的?

Thanks.

谢谢。

2 个解决方案

#1


2  

Though you certainly could make it work with a single table, you probably want to use several tables to store the content. A basic implementation might look like:

虽然您当然可以使用一个表来实现它,但是您可能需要使用几个表来存储内容。一个基本的实现可能是这样的:

  • One table for the periodical list of blog entries you have with columns for blog ID, perma-link/url, etc
  • 一个表格,用来列出你的博客条目,以及你的博客ID、perma-link/url等列
  • One table for the tags associated with each blog id
  • 与每个博客id相关联的标签的一个表
  • One table for the blog entries themselves, consisting of a blog ID, blog body, etc
  • 博客条目本身的一个表,包括博客ID、博客正文等
  • One table for comments, with blog ID, comment ID, comment body, etc
  • 一个表用于评论,包含博客ID、评论ID、评论体等

Everything would be linked together in the tables by the various IDs (blog ID, comment ID, etc) and your engine would load and render the body elements as specified by the ID requested.

所有内容都将通过各种ID (blog ID、注释ID等)在表中链接在一起,您的引擎将按照所请求的ID加载和呈现主体元素。

Images, attachments, etc would be stored on a fileserver, and the rendered content would have hyperlinks to them.

图像、附件等将存储在一个文件服务器上,呈现的内容将具有到它们的超链接。

This is by far a simplistic envisioning of it, and doesnt cover many aspects or issues. For instance, if you plan to store content such as images, etc in your DB you will need to have unique pointers for those, tables for those items and a way to resolve them as part of your MVC framework.

到目前为止,这只是一个简单的设想,并没有涉及很多方面或问题。例如,如果您打算在DB中存储图像等内容,那么您将需要为这些内容提供唯一的指针,为这些项目提供表,以及作为MVC框架的一部分解决它们的方法。

Start simple, and build up from there if you are just learning. Just build each table as you need it and go from there.

从简单做起,如果你只是在学习,那就从简单做起。只要根据需要构建每个表,然后从那里开始。

#2


0  

Not sure which DB you are using but assume SQL server for this example. You can store your blog content in a field as nvarchar(MAX). i dont see any issues with doing this

不确定使用的是哪个DB,但假设本例使用的是SQL server。您可以将博客内容存储在一个名为nvarchar(MAX)的字段中。我认为这样做没有任何问题。

#1


2  

Though you certainly could make it work with a single table, you probably want to use several tables to store the content. A basic implementation might look like:

虽然您当然可以使用一个表来实现它,但是您可能需要使用几个表来存储内容。一个基本的实现可能是这样的:

  • One table for the periodical list of blog entries you have with columns for blog ID, perma-link/url, etc
  • 一个表格,用来列出你的博客条目,以及你的博客ID、perma-link/url等列
  • One table for the tags associated with each blog id
  • 与每个博客id相关联的标签的一个表
  • One table for the blog entries themselves, consisting of a blog ID, blog body, etc
  • 博客条目本身的一个表,包括博客ID、博客正文等
  • One table for comments, with blog ID, comment ID, comment body, etc
  • 一个表用于评论,包含博客ID、评论ID、评论体等

Everything would be linked together in the tables by the various IDs (blog ID, comment ID, etc) and your engine would load and render the body elements as specified by the ID requested.

所有内容都将通过各种ID (blog ID、注释ID等)在表中链接在一起,您的引擎将按照所请求的ID加载和呈现主体元素。

Images, attachments, etc would be stored on a fileserver, and the rendered content would have hyperlinks to them.

图像、附件等将存储在一个文件服务器上,呈现的内容将具有到它们的超链接。

This is by far a simplistic envisioning of it, and doesnt cover many aspects or issues. For instance, if you plan to store content such as images, etc in your DB you will need to have unique pointers for those, tables for those items and a way to resolve them as part of your MVC framework.

到目前为止,这只是一个简单的设想,并没有涉及很多方面或问题。例如,如果您打算在DB中存储图像等内容,那么您将需要为这些内容提供唯一的指针,为这些项目提供表,以及作为MVC框架的一部分解决它们的方法。

Start simple, and build up from there if you are just learning. Just build each table as you need it and go from there.

从简单做起,如果你只是在学习,那就从简单做起。只要根据需要构建每个表,然后从那里开始。

#2


0  

Not sure which DB you are using but assume SQL server for this example. You can store your blog content in a field as nvarchar(MAX). i dont see any issues with doing this

不确定使用的是哪个DB,但假设本例使用的是SQL server。您可以将博客内容存储在一个名为nvarchar(MAX)的字段中。我认为这样做没有任何问题。