Skip to content

Create a generic relational model #18

@rofr

Description

@rofr

Users should be able to use the CRUD pattern to store entities objects of any type. Entities that refer to each other should use foreign keys, not references.
Something like:

  var db = Db.For<Relational>();
  db.CreateTable<Product>();
  var product = new Product();
  db.Insert(product);
  product.Name = "Coconuts";
  db.Update(product);
  db.Delete(product);

Some things to discuss:

Identity

Each entity needs to have a unique identity. We could allow a [Key] attribute on one or more fields, look for a field named Id or just let the user implement IComparable on each Entity. We could support all of these or a subset.

Generated keys

User assigned numeric keys is a problem, there is a risk for duplicates. We could just recommend guids but that takes away options from the user. Also guids use more memory than integer types.
If the server generates during INSERT we might need the generated value to set as FK in related entities. These may also have to be in the same transaction.

Constraints

Constraints should probably be on the entity itself, using plain OO. Except unique constraints, we could use indexes for that.

Indexes

Creating indexes would be useful. Something like:
db.Index<Product>("Product.Name", p => p.Name);
We would have to serialize the lambda to make this work with a remote server.

How will origodb server know the user defined entity types?

Running embedded the user can put custom entities in a generic model but remote, the server needs to be able to load the types. One way would be to just add assemblies in the server UI but this kind of defeats the purpose of a generic model in the first place.

Here's an old blog article with some ideas
http://origodb.com/2011/11/24/relational-modeling-and-crud.html
EDIT: Link updated

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions