More

Moving from XOD 1.x

XOD 2 keeps the 1.x API and attributes, opens 1.x databases, and adds new features you can use when you need them.

XOD 2 is a rework of the 2017 library (Xod 0.1.x and Xod.Core), built for .NET 8 and .NET 9. Code written for 1.x compiles against XOD 2 with few or no changes, and XOD 2 opens 1.x databases. The 1.x code is on the legacy branch.

Upgrading

  1. Move the project to .NET 8 or .NET 9.

  2. Replace the Xod 0.1.x or Xod.Core reference with the current Xod package:

    dotnet add package Xod
  3. Back up the database folder, then open it as before:

    using Xod;
    
    using var db = new XodContext(@"c:\xod\data.xod");
    var item = db.Find<ToDo>(s => s.Id == 1);
    item.Done = true;
    db.Update(item);
  4. Run your tests against a copy of the real data before switching production over.

What stays the same

  • The namespace (Xod) and the entry point (XodContext).
  • Insert, Update, Delete, Find, FirstMatch, Query, Select, Count, Drop and the other 1.x methods.
  • The attributes: [PrimaryKey], [UniqueKey], [ForeignKey], [Children], [ParentKey], [Property], [Crypto], [Markup], [Required], [NotMapped], [GenericTypeProperty].
  • The XML file format.

What’s better

  • Indexes. Lookups by key and by indexed property use B-tree indexes instead of scans.
  • Unique keys are enforced on insert and on update.
  • Transactions: a commit that a process crash cuts short is undone from its journal.
  • Concurrency: many readers at once, with writes serialized one at a time inside one context.
  • [Children] and [ParentKey] are optional when names follow the convention.

What’s new

  • Insert<T> returns the typed object with its key filled in.
  • JSON and binary storage formats, and XodMigrator to convert. See Storage.
  • BeginTransaction(). See Transactions.
  • SQL SELECT from .NET (db.Sql) and the xod query CLI. See Reading data.
  • Async methods. See Reading data.
  • SHA256, SHA512 and reversible AES256 property crypto. See Security.
  • DateOnly, TimeOnly, DateTimeOffset, dictionaries with preserved string comparers, and records.

Things to check

  • Cascade. Children collections cascade deletes: deleting a parent deletes its children and its plain lists of objects without a key. Check that this matches what your code expects (see Relationships).
  • MD5 and SHA1 hashes from 1.x. Use SHA256 or SHA512 for new data. CryptoHelper.VerifyHash and SQL’s VERIFY_HASH verify values against 1.x digests (decimal digits) as well as 2.x digests (hex), and updating a row preserves its stored 1.x digest. Open a 1.x database with DatabaseOptions.Legacy1xDigests = true so 1.x digests also stay intact when written elsewhere (inserted into another database, copied to another row, or rewritten with a parent); leave it off if [Crypto] properties may store plain digit strings.
  • A bare [Crypto] hashes with SHA256 in XOD 2, where 1.x used MD5. Specify [Crypto(CryptoMethod.MD5)] explicitly if you need new values hashed with MD5.
  • Encrypted 1.x databases. Encrypted 1.x databases open with their password. ASCII passwords open directly; non-ASCII passwords open in the form 1.x hashed them (? for non-ASCII characters; databases encrypted by pre-September-2016 1.x builds can’t be opened). Files keep 1.x’s unsalted key until you run ChangePassword, so change the password after migrating.
  • Empty strings. Empty strings stored by 1.x read back as "" (see Values read back as written).
  • Already on XOD 2? See Upgrading for version-to-version changes within 2.x.
  • Licence. XOD 2 is Apache-2.0. The 0.1.x line and the 1.0.0 betas stay under MIT.

Source on GitHub · Report a problem with this page