J
Try to come on the other side, and see what's happening now to work with the OBD. For example, a book is very good for this. https://www.ozon.ru/context/detail/id/1616782/ for authorizing a team of developers, the principal of which is Martin Fowler.In the book, most of the descriptions of patters for work with the OBD. In addition, the book introduces Standard names for these patters. What you called Providermost likely Repository (repository). The use of common terminology facilitates understanding. It also describes important issues. requests (query builders), Data converters (data mappers) and units of work (units of work).If you write ORM on your own, you will certainly need to implement this. The second point is to look at the existing ORM and to determine how these issues are addressed there. For example, Entity Framework has a concept data sets (sighs)DbSet<TEntity>) It's not a patterne, it's a class name where several pathters are executed and, in particular, a vault.They're all in class. DbContextwhich is an analog to you. DbProvider♪ It also runs several pathers, including Unit of work♪ The whole logic of the box is in the unit of work, in the method DbContext.SaveChanges♪ First with help DbSet<TEntity>.Add I need you to. register in the context of new facilities, and then cause DbContext.SaveChangeswho's gonna decide to write it down first and then what?The Context also performs a reversal operation to fill objects with table values, i.e. pattern Data converter♪ I haven't looked deeply into the code, but I understand there's one universal converter for all tables and classes.And the last question is the connections between the essences. In EF and NHibernate communications are implemented by so-called navigational properties:[Table("Categories")]
public class Category
{
[Key]
public int Id { get; set; }
[MaxLength(200)]
public string Name { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
[Table("Products")]
public class Product
{
public int Id { get; set; }
public int CategoryId { get; set; }
public virtual Category Category { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
}
In this example, all properties are directly displayed in the field in tables other than two. navigation: Category.Products and Product.Category♪ In doing so, EF itself understands that these navigational properties must not be downloaded or stored. He also understands that there is a connection between one and a few and that the field is connected. Product.CategoryId♪ However, as can be seen from the example, the default of EF can be changed by attribution.EF implements pattern left load (lazy loading), so under certain conditions, underground Facilities accessible through navigational properties. If it turns out to be too slow, you can give an EF subpoena, which items will be required accurately and which are better downloaded.Maybe your ORM needs to focus on such solutions. Or play with existing ORM, such as Entity Framework, NHibernate, Dapper. Perhaps you'll abandon the idea of creating your own ORM because most of what you need has already been realized.