Path: redb/redb.Examples/Ef/DepartmentEfMapping.cs Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Examples/Ef/DepartmentEfMapping.cs ---- using Microsoft.EntityFrameworkCore; using redb.Core.Models.Entities; using redb.Examples.Ef.Entities; using Biz = redb.Examples.Models; namespace redb.Examples.Ef; /// /// The department tree of the examples through EF Core: a node is a header row in objects (its parent in /// _id_parent) with a DepartmentProps row, turned into the redb /// hands out. EF has no recursive query and no depth parameter, so its twins cover the operations on one level: /// create, delete, move, count, roots, leaves and direct children. /// internal static class DepartmentEfMapping { /// A new node under (a root when null). Keys come from the database. public static objects ToEntity(string name, string code, string description, decimal budget, objects? parent) { var now = DateTime.UtcNow; return new objects { _id_scheme = EfSchemeIds.Department, _id_owner = 0, _id_who_change = 0, _date_create = now, _date_modify = now, _name = name, _id_parentNavigation = parent, DepartmentProps = new DepartmentProps { Name = name, Code = code, Description = description, Budget = budget, IsActive = true } }; } /// Every department node with its header, as a query. public static IQueryable Nodes(this FlatContext db) => db.DepartmentProps.Include(d => d.objects); /// The business object of a loaded department node, without parent or children. public static TreeRedbObject ToBusiness(DepartmentProps d) { var h = d.objects; return new TreeRedbObject { id = h._id, parent_id = h._id_parent, scheme_id = h._id_scheme, owner_id = h._id_owner, who_change_id = h._id_who_change, date_create = h._date_create, date_modify = h._date_modify, date_begin = h._date_begin, date_complete = h._date_complete, key = h._key, name = h._name, note = h._note, value_long = h._value_long, value_string = h._value_string, value_guid = h._value_guid, value_bool = h._value_bool, value_double = h._value_double, value_numeric = h._value_numeric, value_datetime = h._value_datetime, value_bytes = h._value_bytes, Props = new Biz.DepartmentProps { Name = d.Name ?? string.Empty, Code = d.Code ?? string.Empty, Description = d.Description ?? string.Empty, IsActive = d.IsActive ?? false, Budget = d.Budget ?? 0m } }; } }