我对asp.net mvc相当陌生,而且我目前有一个显示大量错误的应用程序。我有2页包含应用程序错误和日志错误。数据来自2个不同的数据库,但我想要在一个页面上显示来自两个数据库的数据。在MVC中结合来自2个数据库的数据
这些表具有不同名称的标题,表示相同的东西,例如Application Database中的ApplicationName与Log Database中的LogName是一样的。
下面是我目前拥有的一个小例子,以及我想要的一个例子。
当前
Application Errors
ID ApplicationName ApplicationMessage ApplicationDate
1 Something Hello World 01/01/2015
2 Something Else Another Message 03/01/2015
Log Errors
ID LogName LogMessage LogDate
1 Some Log A log message 02/01/2015
2 Another Log Another Log Message 04/01/2015
我想
Internal Errors
ID Name Message Date
1 Something Hello World 01/01/2015
2 Some Log A log message 02/01/2015
3 Something Else Another Message 03/01/2015
4 Another Log Another Log Message 04/01/2015
在分钟什么,我对每个数据库2个独立的模型,但我想我需要两个模型合并为一个模型结合他们两个,但我不确定如何做到这一点。我如何能够将两个数据源合并在一起以在同一页面中显示数据?
现有型号
应用
[Table("ELMAH_Error")]
public class ElmahError
{
[Key]
public System.Guid ErrorId { get; set; }
public System.String Application { get; set; }
public System.String Host { get; set; }
public System.String Type { get; set; }
public System.String Source { get; set; }
public System.String Message { get; set; }
public System.String User { get; set; }
public System.Int32 StatusCode { get; set; }
public System.DateTime TimeUtc { get; set; }
public System.Int32 Sequence { get; set; }
public System.String AllXml { get; set; }
}
登录
[Table("LogEntry")]
public class LogEntry
{
[Key]
public Int64 ID { get; set; }
public DateTime LogDate { get; set; }
public Int16 Priority { get; set; }
public string SourceClass { get; set; }
public string Category { get; set; }
public string Message { get; set; }
public string UserID { get; set; }
public string ProcessID { get; set; }
}
从模型中,有一些领域,我想合并,以及作为与我不相似的字段也喜欢包括。下面的模型显示了我想要的,但我不知道如何实现它。
内部错误
public class InternalErrors
{
public string Id { get; set; } //L:ID && E:ErrorId
public int Priority { get; set; } //L:Priority
public string Application { get; set; } //L:SourceClass && E:Application
public string Message { get; set; } //L:Message && E:Message
public string Type { get; set; } //L:Category && E:Type
public string User { get; set; } //L:UserID && E:User
public string ProcessID { get; set; } //L:ProcessID
public DateTime Date { get; set; } //L:LogDate && E:TimeUtc
public int StatusCode { get; set; } //E:StatusCode
public string AllXml { get; set; } //E:AllXml
public int Sequence { get; set; } //E:Sequence
public int ErrorCount { get; set; } //E:ErrorCount
}
我希望这是足够的信息,为您提供一个答案,如果你有什么事,让我知道。
在此先感谢
你在说这个https://dotnetfiddle.net/mrWGDn吗? –
你用什么来连接数据库? EF,raw ado.net,它是什么?您可能还想将其添加为标签。 – gldraphael