Skip to content

Shorthand syntax for creating entites #39

Open

Description

@tpluscode

It would be very handy to use anonymous objects to create entities, especially ones with a blank id. Currently a blank node id must be explicitely created

var entity = context.Load<IPerson>("some URI");
var blankId = entity.CreateBlankId();
var address = context.Create<IAddress>(blankId);
address.City = "New York";
entity.Address = address;

Here's how this could work instead

var entity = context.Load<IPerson>("some URI");
entity.Address = new {
   City = "New York"
};

Internally a new blank identitifier would be generated for the anonymous object and each property would be translated to the destination type. In this case the properties would have to match those of IAddress.

Activity

  1. tpluscode commented on Sep 23, 2014

    @tpluscode
    ContributorAuthor

    Additionally it could be possible to declare an Id property. If present it would be used instead of the generated blank node identified.

    var entity = context.Load<IPerson>("some URI");
    entity.Mother = new {
       Id = new Uri("the mother's id"),
       Name = "Theresa"
    };

    The question is how should the Name property be treated? After all it is possible that an entity already exists for the given Uri. Should the supplied values replace whatever values the already existed.

  2. tpluscode commented on Sep 23, 2014

    @tpluscode
    ContributorAuthor

    Lastly the IEntityContext could be extended to enable creating new entities in a concise way.

    dynamic myself = new {
       Id = "http://example.org/about#me",
       Name = "Tomasz",
       LastName = "Pluskiewicz"
    };
    context.Add<IPerson>(myself);

    Similarly to my previous comment it remains to be decided what should happen if the entity already exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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