首先,你必須使用屬性,而不是字段然後用精緻小巧的multi-mapping:
public class Employee
{
public int Id { get; set; }
public string Location { get; set; }
public EType EType { get; set; }
}
public class EType
{
public int TypeId { get; set; }
public string TypeName { get; set; }
}
[TestFixture]
public class MultimappingTest
{
[Test]
public void TestSplit()
{
using (var conn = new SqlConnection(@"Data Source=.\sqlexpress;Integrated Security=true; Initial Catalog=foo"))
{
var result =
conn.Query<Employee, EType, Employee>(@"select Id = 1, Location = 'earth', TypeId = 2, TypeName = 'human'",
(employee, type) =>
{
employee.EType = type;
return employee;
}, splitOn: "TypeId").First();
Assert.That(result.EType.TypeId == 2);
Assert.That(result.EType.TypeName == "human");
}
}
}
非常感謝您的幫助反正是有。來處理插入和更新?將EType自動分成Typeid和Type名稱 –
不是我知道的... –