现有的SQL Server表.INCLUDE部队EF扔序列不包含任何元素
两个测试:
呼叫这一个:
[Test]
public void AssertAccessPolicyWithIdAndChecksum()
{
var pol = Repo.GetPolicyFlightStatus(aut_id: 44544, checksum: "QXSDENY");
Assert.NotNull(pol);
}
调用此一架B
[Test]
public void AssertGetFriendlyPolicy()
{
var lineRepo = new tbl_StatusRepository();
var pol = Repo.GetPolicyFlightStatus(aut_id: 44544, checksum: "QXSDENY");
Assert.AreEqual("With Underwriter", pol.tbl_Status.txt_friendlyName);
Assert.AreEqual("WC/Longshore", pol.tbl_Line.txt_friendlyName);
}
型号:
public partial class tbl_Policy
{
[Key]
public int aut_id { get; set; }
[ForeignKey("tbl_Status")]
public int int_statusID { get; set; }
public virtual tbl_Status tbl_Status { get; set; }
[ForeignKey("tbl_Line")]
public int int_lineID { get; set; }
public virtual tbl_Line tbl_Line { get; set; }
}
public class tbl_Status
{
[Key]
public int aut_id { get; set; }
public string txt_status { get; set; }
public string txt_friendlyName { get; set; }
public virtual tbl_Policy tbl_Policy { get; set; }
}
public class tbl_Line
{
[Key]
public int aut_id { get; set; }
public string txt_Line { get; set; }
public string txt_friendlyName { get; set; }
public virtual tbl_Policy tbl_Policy { get; set; }
}
当运行
internal static tbl_Policy GetPolicyFlightStatus(int aut_id, string checksum)
{
if (Transcoder.Transcode(aut_id) == checksum)
{
var ctx = new LIGDataContext();
return ctx.tbl_Policy.Include("tbl_Line").Include("tbl_Status").Single(f => f.aut_id == aut_id);
}
return null;
}
种皮传递 TESTB抛出异常上第一断言线
添加包括用于子表
internal static tbl_Policy GetPolicyFlightStatus(int aut_id, string checksum)
{
if (Transcoder.Transcode(aut_id) == checksum)
{
var ctx = new LIGDataContext();
return ctx.tbl_Policy.Include("tbl_Line").Include("tbl_Status").Single(f => f.aut_id == aut_id);
}
return null;
}
试验A和试验B投掷 LIG2010RedesignMVC3。 LIGMVC2010FlightTrackerT ests.AssertAccessPolicyWithIdAndChecksum: System.InvalidOperationException:序列不包含任何元素
LIG2010RedesignMVC3.LIGMVC2010FlightTrackerTests.AssertGetFriendlyPolicy: System.InvalidOperationException:序列不包含任何元素
我试图做一个一对多所以这就是一些帮助,现在我只需要弄清楚为什么我的映射仍然是错误的 – MarkKGreenway 2011-01-25 05:19:11