首先,你必须使用属性,而不是字段然后用精致小巧的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名称 –
不是我知道的... –