在我的应用程序中,我想blind_copy_recipients
从 SQL Server 2012 中的数据库“MSDB”中的系统表“sysmail_mailitems”中检索。我在 C# Web 应用程序中使用实体框架来查询数据库。sysmail_mailitems
我创建了一个从中读取数据的类和方法。但它实际上使用此名称在系统表之外创建了一个新表。我的目标不是创建一个表,而只是从现有表中读取。谁能指导我如何做到这一点?
代码:
public class sysmail_mailitem
{
[Key]
public Int32 mailitem_id { get; set; }
public Int32 profile_id { get; set; }
public String recipients { get; set; }
public String copy_recipients { get; set; }
public String blind_copy_recipients { get; set; }
public String subject { get; set; }
public String from_address { get; set; }
public String reply_to { get; set; }
public String body { get; set; }
public String body_format { get; set; }
public String importance { get; set; }
public String sensitivity { get; set; }
public String file_attachments { get; set; }
public String attachment_encoding { get; set; }
public String query { get; set; }
public String execute_query_database { get; set; }
public Boolean? attach_query_result_as_file { get; set; }
public Boolean? query_result_header { get; set; }
public Int32? query_result_width { get; set; }
public String query_result_separator { get; set; }
public Boolean? exclude_query_output { get; set; }
public Boolean? append_query_error { get; set; }
public DateTime send_request_date { get; set; }
public String send_request_user { get; set; }
public Int32? sent_account_id { get; set; }
public Byte? sent_status { get; set; }
public DateTime? sent_date { get; set; }
public DateTime last_mod_date { get; set; }
public String last_mod_user { get; set; }
}
public String GetMailRecipients(Int32 mailItemId)
{
using(MSDBContext _db = new MSDBContext())
{
var query = (from mailItems in _db.MailItems
where mailItems.mailitem_id == mailItemId
select mailItems).FirstOrDefault();
try
{
return query.blind_copy_recipients;
}
catch (NullReferenceException) { }
return "N/A";
}
}
public class MSDBContext : DbContext
{
public MSDBContext() : base("msdb") { }
public DbSet<sysmail_mailitem> MailItems { get; set; }
}