1.8 KiB
1.8 KiB
Mapping and Entities
DynamORM supports attribute-driven mapping and entity lifecycle helpers.
Mapping Attributes
TableAttribute
[Table(Name = "users", Owner = "dbo", Override = true)]
public class User
{
// ...
}
Name: table name override.Owner: schema/owner segment.Override: prefer attribute schema info over provider schema.
ColumnAttribute
public class User
{
[Column("id", isKey: true)]
public int Id { get; set; }
[Column("email")]
public string Email { get; set; }
}
Important flags:
IsKeyAllowNullIsNoInsertIsNoUpdateType,Size,Precision,Scale
Ignore Fields
Use IgnoreAttribute to skip properties in mapper-driven workflows.
Validation
RequiredAttribute can define value rules.
public class Profile
{
[Required(1f, 10f)]
public int Rank { get; set; }
[Required(2, true)]
[Required(7, 18, ElementRequirement = true)]
public decimal[] Scores { get; set; }
}
var issues = DynamicMapperCache.GetMapper<Profile>().ValidateObject(profile);
Validation scenarios are verified in DynamORM.Tests/Helpers/Validation/ObjectValidationTest.cs.
DynamicEntityBase
DynamicEntityBase tracks state and changed fields.
public class UserEntity : DynamicEntityBase
{
[Column("id", true)]
public int Id { get; set; }
[Column("first")]
public string First { get; set; }
}
Available behaviors:
Validate()Insert(db)Update(db)Delete(db)Refresh(db)Save(db)driven byDynamicEntityState
Repository Base
DynamicRepositoryBase<T> provides common operations:
GetAll()GetByQuery(...)Insert(...)Update(...)Delete(...)Save(...)
It ensures query/table compatibility for T unless explicitly bypassed.