ASP.NET MVC4 + Razor on Mono + EF 6 DateTime崩溃

时间:2014-08-29 22:48:07

标签: c# asp.net-mvc-4 iis mono

我正在尝试使用Mono运行应用程序。它在IIS上运行正常,但我希望它在Mono上运行。但它总是把它扔给我:

  

'Article'上的'CreateDate'属性无法设置为'System.String'值。您必须将此属性设置为类型为“System.DateTime”的非null值。

事实是它抛出的地方是:

public Article[] Select(int number)
        {
            return DbContextProvider.Current.Set<Article>()
                .OrderByDescending(n => n.CreateDate)
                .Take(number)
                .ToArray();
        }

System.String没有任何用法。实际上,它转换为字符串的唯一地方是:

@using BaseSite.Extensions.DateTimeExtensions
@model Classic.Views.Home.Articles.ArticleViewModel

<div class="article-wrapper">
    <div class="article-title">
        @Html.ActionLink(Model.Title, "Index", "Articles", new RouteValueDictionary{{"articleId", Model.ArticleId}}, null)
    </div>
    @Html.Raw(Model.Text)
    <div class="article-data date">
        @Html.ActionLink(Model.UserId, "Index", "Profile", new RouteValueDictionary{{"userId", Model.UserId}}, null),
        @Model.CreateDate.Format(true)
    </div>
</div>

但错误在此之前被抛出。而且,它适用于IIS,只有在Mono上才会出现这样一个奇怪的错误。

数据库表格布局为:

CREATE TABLE [dbo].[Articles](
    [ArticleId] [uniqueidentifier] NOT NULL,
    [UserId] [nvarchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    [CreateDate] [datetime2](7) NOT NULL,
    [Title] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    [Text] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
PRIMARY KEY CLUSTERED 
(
    [ArticleId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

映射类:

using System;

namespace BusinessObjects.Articles
{
    public class Article
    {
        public Guid ArticleId { get; set; }
        public string UserId { get; set; }
        public DateTime CreateDate { get; set; }

        public string Title { get; set; }
        public string Text { get; set; }
    }
}

using System.Data.Entity;

namespace BusinessObjects.Articles
{
    public class ArticleMapper : IDbMapper
    {
        public void Map(DbModelBuilder modelBuilder)
        {
            var entity = modelBuilder.Entity<Article>();

            entity.HasKey(n => n.ArticleId);
            entity.Property(n => n.ArticleId).IsRequired();

            entity.Property(n => n.UserId).IsRequired().HasMaxLength(30);
            entity.Property(n => n.Title).IsRequired().HasMaxLength(50);
            entity.Property(n => n.Text).IsRequired().IsMaxLength();
        }
    }
}
是的,是的。我还有其他表与DateTime,他们都得到了这个错误。它们都在IIS(MS Stack)上正常运行,它只在Mono + xsp4上出错。 有人可以提供任何帮助吗?我厌倦了这种疲惫。

PS:我试过几乎所有的单声道版本,现在我在Mono git master 3.8.1(master / 38c3874),同样的东西有3.6,3.2.8等

1 个答案:

答案 0 :(得分:1)

正如AlexanderKöplinger所提到的,似乎是Mono中“datetime2”的错误。通过从MsSql迁移到PostgreSql来修复 - 它在计划中。