【发布时间】:2012-12-10 16:16:52
【问题描述】:
我正在显示我的数据库中的一条记录。该记录从其他表中提取数据并使用主表中的 Int 来表示值,因此 Item 表的 Division 等于 1 并且 Division 表 1 = ALL 。现在我正在显示记录,我试图将 1 变为全部。所有 ID 字段都显示 int。这就是我的代码告诉它要做的事情。但我正在尝试显示名称,当我这样做时,我会得到很多红色。它找不到名称。 CatagoryID 应该是 CategoryName。
希望这是有道理的。
if (!IsPostBack)
{
string v = Request.QueryString["ContactID"];
int itemid;
int.TryParse(v, out itemid);
var customerInfo = GetCustomerInfo(itemid);
CONTACTID.Text = customerInfo[0].ContactID.ToString();
ContactTitle.Text = customerInfo[0].ContactTitlesID.ToString();
ContactNameB.Text = customerInfo[0].ContactName;
DropDownAddCategory.Text = customerInfo[0].CategoryID.ToString();
DDLAddDivision.Text = customerInfo[0].DivisionID.ToString();
ContactPhoneBox.Text = customerInfo[0].ContactOPhone;
ContactCellBox.Text = customerInfo[0].ContactCell;
ContactEmailBox.Text = customerInfo[0].ContactEmail;
CextB.Text = customerInfo[0].Ext;
}
private List<Solutions.Models.Contact> GetCustomerInfo(int itemid)
{
using (ItemContext context = new ItemContext())
{
return (from c in context.Contacts
where c.ContactID == itemid
select c).ToList();
}
}
这是模型
public class Contact
{
[ScaffoldColumn(false)]
public int ContactID { get; set; }
public System.DateTime ContactCreated { get; set; }
public string ContactName { get; set; }
public int? ContactTitlesID { get; set; }
public string ContactOPhone { get; set; }
public bool cApproved { get; set; }
public string User { get; set; }
public string ContactCell { get; set; }
public string ContactEmail { get; set; }
public int? DivisionID { get; set; }
public int? CategoryID { get; set; }
[StringLength(5)]
public string CExt { get; set; }
public virtual Division Division { get; set; }
public virtual Category Category { get; set; }
public virtual ContactTitle ContactTitle { get; set; }
public string Ext { get; set; }
}
【问题讨论】:
-
你需要充实一下。 'get a lot of red' 并不能帮助我们回答您的问题。另外,尝试显示名称...在哪里?
-
它不是从 Other 表中获取数据以提取我正在寻找的 CategoryName。它只显示当前表的值。在这种情况下,
context.Contacts是唯一能够显示的数据。 -
您的映射是什么样的?我假设您使用的是 linq to sql?
-
@alexjamesbrown 我添加了模型。
-
你的问题中遗漏了一条关键信息......我已经适当地标记了你的问题
标签: c# asp.net linq entity-framework ef-code-first