Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shorthand syntax for creating entites #39

Open
tpluscode opened this issue Sep 23, 2014 · 2 comments
Open

Shorthand syntax for creating entites #39

tpluscode opened this issue Sep 23, 2014 · 2 comments

Comments

@tpluscode
Copy link
Contributor

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.

@tpluscode
Copy link
Contributor Author

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.

@tpluscode
Copy link
Contributor Author

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
Projects
None yet
Development

No branches or pull requests

1 participant