ASP.NET MVC4 + Razor on Mono + EF 6 DateTime崩溃 [英] ASP.NET MVC4 + Razor on Mono + EF 6 DateTime crash
问题描述
我正在尝试使用Mono运行应用程序。它在IIS上运行正常,但我希望它在Mono上运行。但它总是把它扔给我:
I am trying to run an application with Mono. It runs fine on IIS, but I want it run on Mono. But it always throw this to me:
'Article'上的'CreateDate'属性无法设置为'System.String'值。您必须将此属性设置为类型为System.DateTime的非null值。
The 'CreateDate' property on 'Article' could not be set to a 'System.String' value. You must set this property to a non-null value of type 'System.DateTime'.
事实是它抛出的地方是:
The fact is that the place where it is thrown is this:
public Article[] Select(int number)
{
return DbContextProvider.Current.Set<Article>()
.OrderByDescending(n => n.CreateDate)
.Take(number)
.ToArray();
}
无法使用System.String。实际上,它转换为字符串的唯一地方是:
There is nowhere any usage of System.String. Actually, the only place it gets converted to a string, is here:
@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上才会出现这样一个奇怪的错误。
But the error is being thrown a way before that. And, it works on IIS, only on Mono there is such a strange bug.
数据库表布局是:
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上出错。
任何人都可以提供任何帮助吗?我迷失了这种疲惫。
And yeah. I have also other tables with DateTime, they all get that error. And they all runs normally on IIS (MS Stack), it only bugs on Mono + xsp4. Can anyone provide any help? I am lost with that weiredness.
PS:我尝试了几乎所有的单声道版本,现在我在Mono git master 3.8.1(master / 38c3874),同样的事情3.6,3.2.8等
PS: I tried nearly all mono versions, right now I am at Mono git master 3.8.1 (master/38c3874), same thing with 3.6, 3.2.8 etc
推荐答案
正如AlexanderKöplinger所说,似乎是Mono中datetime2的错误。通过从MsSql迁移到PostgreSql来修复 - 它在计划中。
As Alexander Köplinger mentioned, seems to be a bug of "datetime2" inside Mono. Fixed by migrating away from MsSql to PostgreSql - it was in the plans.
这篇关于ASP.NET MVC4 + Razor on Mono + EF 6 DateTime崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!