-
Notifications
You must be signed in to change notification settings - Fork 11
Home
Bart Read edited this page Dec 11, 2015
·
29 revisions
Dapper.SimpleSave simplifies the process of saving complex object hierarchies to a relational database.
- Find out more - documentation table of contents
- Get involved - how to contribute
- Get involved in the discussion on our Google Group
- Report issues or provide feedback/suggestions
- License
If instead (or in addition) you need to load complex object hierarchies from a relational database, check out Dapper.SimpleLoad, which obviates the need to write complex and hard to maintain Dapper multi-mapping code.
##Example
[Table("[user].USER_MST")]
public class UserDao
{
[PrimaryKey]
public int? UserKey { get; set; }
public Guid UserGUID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string PasswordSalt { get; set; }
[Column("UserStatusKey")]
[ManyToOne]
public UserStatusEnum Status { get; set; }
public string CountryCode { get; set; }
public string PersonalMobileNumber { get; set; }
public string BusinessMobileNumber { get; set; }
[Column("OfficeNumberKey")]
[OneToOne]
[ForeignKeyReference(typeof(OfficeNumberDao))]
public OfficeNumberDao OfficeNumber { get; set; }
public string VirtualLineNumber { get; set; }
public string EmailAddress { get; set; }
public int PasswordFailureCount { get; set; }
[ManyToOne]
[Column("PositionKey")]
public PositionDao Position { get; set; }
[ManyToMany("[user].USER_DEPARTMENT_LNK")]
public IList<DepartmentDao> Department { get; set; }
[ManyToMany("[user].USER_ADDITIONAL_ROLES_LNK")]
public IList<RoleDao> AdditionalRoles { get; set; }
[ManyToMany("[user].USER_TEAM_LNK")]
public IList<TeamDao> Team { get; set; }
}
...
var user = new UserDao {
FirstName = "Marty",
LastName = "McFly",
Username = "marty.mcfly",
Department = new List<DepartmentDao> {
new DepartmentDao {
Name = "Time Travel"
}
}
....
}
using (var connection = new SqlConnection(connectionString))
{
// INSERTs rows for UserDao, DepartmentDao, and other child objects
// in the relevant tables.
connection.Create(user);
}
##Documentation
- Getting Started
- How can Dapper.SimpleSave help me?
- Tutorial: Saving data to a database
- Configuring the behaviour of Dapper.SimpleSave with attributes
- Transactions
- Extension method reference
- Dapper.SimpleSave and cardinality - 1:1, 1:N, N:1, and M:N relationships
- How does Dapper.SimpleSave work?
- Known and intended limitations
- FAQ