We have a list of entities on the front-end (each entity in the list does not have all the entity details).
Our goal is to make a clone for specific entity from a list.
Example for entity:
Name | Type | SomeFieldA | SomeFieldB
We already have a create-entity API, that receives the details for the new entity.
To implement the entity clone I'm thinking about two possible solutions:
Possible solution one:
Get policy details from the server by policy ID
Use the existing create entity API to do a clone
Pros:
We are using the same exist API for clone
Possible solution two:
Create new API that will receive a policy ID and will do the clone on the server side
Pros:
More user friendly API
Less requests to the server
Which approach do you think is the better here and why?
Related
We're creating a WebAPI using Entity Framework in MVC 4. Our client wants to send complex objects containing related objects - both new and updated. The root object maybe new or existing one too. The client generates primary keys - we're using Guids for that. So on server we really can't tell that we got an existing object update or a new one. What would be the best way to handle this situation? We need some sort of add or update functionality and it's not yet clear to us how to proceed with Entity Framework for this.
EF doesn't have any build in support for discovering changes in detached object graph. You either have to include some field into every object describing if the object is new, not modified, updated or deleted (you will also need similar behavior to track changes in many-to-many relationships). If you don't use such field you have no other way than querying database and comparing current DB state with data received from client to find what has changed.
I'm using ASP.NET MVC3 with Entity Framework 4.
I am using the Unit Of Work + Generic Repository pattern.
I searched for similar question everywhere, I see that many people have my problem, but still can't find a good and practical solution.
We have a multi-tenant database.
Imagine a database with a similar structure:
customers
groups, associated to a customer
users, associated to one or many groups
And then, for each customer we have
resources, associated to one or many groups, and linked between each other with foreign keys, many-to-many relationships and so on
So, when a user logs in, he is associated to one or many groups, and he needs to have access to the parent and child resources associated to that groups.
Now the problem is:
I implemented a sort of pre-filtering with a .Where() clause into the unit of work, in the repositories, based on the id of the logged in user.
And this is working.
The pre-filtering I did on the repositories is working fine, but of course it works only if you access directly the repository of the sources of TYPE A or TYPE B or TYPE C and so on.
But a resource is linked to other resources with many-to-many tables and foreign keys.
So, it happens that sometimes a resource belongs to a group to which the user has access, but sometimes the resources linked to this resource belong to a group to which the user does not have access.
If I traverse the navigation properties of the "parent" resource, the user can access all the linked resources, even the one belonging to other groups.
So, if you are starting from a TYPE A resource, and traverse the navigation properties to reach the TYPE B and TYPE C resources, they are not filtered.
If you access the TYPE B and TYPE C repositories, they are filtered.
Now my filters, as I said before, are in the Unit Of Work class, but I tried to move them into a custom DBContext, applying the filters directly into the DBSet, but nothing changes:
It seems that EF is accessing directly the database to build the navigation properties, thus not using the other repositories or the other DBSet, avoiding the prefilter.
What can we do?
I see that NHibernate has Global Filters that could accomplish my task, so I'm evaluating a migration from EF to NH.
I see that many other people is asking for .Include() filters, thus disabling lazy loading.
Thank you.
I can provide some piece of code if needed, but I hope I explained my problem correctly.
Thank you i.a.
Best Regards,
Marco
I saw a solution with mapping to views and stored procedures, but I'm not sure how hard it was in development and maintanace. In short, it is possible to map EF model to views, where data will be filtered; in this solution each user have own database credentials.
According to DDD (Blue book, Evans) a Factory has the responsibility to create an Aggregate Root in a valid state. Does this mean it should be able to create the technical id (objectId in mongoDB world) as well as the domain id?
On the one hand, this seems like a technical detail and it would seem okay to let Mongo handle the creation of the ID.
On the other, enabling querying by id (by having getById in a DDD repository) exposes the technical id to the domain, which in turn would make it the responsibility of the Factory to create it.
Perhaps I can't get my head on the different use-cases / overlap, etc. of Technical Id's vs DomainId's or perhaps I'm being overzealous, but I'd appreciate your opinion anyway.
In short:
In DDD: Should a factory be able to create the technical Id as well as the domain Id?
possible implementation: Hi/Lo ( How to set the hilo sequence starting value in MongoDB Norm?)
EDIT: although the hi/lo way exposes the Factory to the persistence layer, which is something only the Repository should know. hmmm
Thanks
Factories don't have to concern themselves with the ID because the validity of an aggregate is orthogonal to identity. Identity can be assigned in a few different ways, either as a incremental ID from a relational database in which case the repository has to manage it, or as a UUID/GUID in which case it can be assigned by the factory, or repository, or even the calling client which is convenient because then the client has the key by default.
Whenever possible, I try to maintain a single identity for aggregates. I'm not sure if MongoDB requires an additional technical ID, but if it does and the domain ID can't be used in its place, then MongoDB should manage it on its own and behind the scenes.
Hierarchy:
abstract Package
ServerPackage: Package
ClientPackage: ServerPackage
In terms of EF CF, all three tables have a one-to-one relationship. Have I selected the right composition to cater to the following scenario?
Scenario:
Abstract Package is created by the server upon request with unique Guid.
Server creates ServerPackage and sends to client.
Client processes ServerPackage and creates a ClientPackage to send back to server.
In other words, as soon as a Package request comes in, a ServerPackage AND a ClientPackage should be created. I am assuming this will not work since I need both packages to be tied to the same abstract Package Id.
Should I be using composition instead of inheritance and force a one-to-one relationship?
Please advise.
It will work only if all your packages are same instance => when the server receives request it must immediately create ClientPackage. It cannot create Package because Package is abstract and if it only creates ServerPackage you will not be able to create ClientPackage with the same Id. So it looks like whole your inheritance will be redundant in such scenario.
If you want to follow your workflow you need composition.
I have 3 entities.
PortalRole, Person and PersonPortalRole
PersonPortalRole is a intersection entity to deal with my Many-Many relationship.
I am using JavaScript through a HTML web resource to allow the creation and removal of this entity. I can create new entities by using the REST service fairly easily but I can't find a way of deleting a intersect record (two lookup fields) using the PersonId and PortalRoleId.
Has anyone had any exposure to either deleting a record through REST using the two foreign keys values from a lookup? I was trying to get the object first using a filter but can't seemt o filter using the lookup primary keys.
Was trying something like below which returns 15 entries to then filter the results to get the primary key, and then delete using that key but not sure on the way to do this.
SERVER/INSTANCE/XRMServices/2011/OrganizationData.svc/personportalrolesSet?$expand=Person,PortalRole
Based on that URI, you are interacting with an OData service. OData uses Atom feeds for returning lists of stuff so you will likely find within each <entry> element a <id> element that contains the URL of the resource. If you issue a HTTP DELETE to that URL then your resource will be deleted.
See docs here http://www.odata.org/developers/protocols/operations#DeletingEntries
I don't use the REST endpoint, but there's no way I know of to end a many-to-many relationship except through sending a Disassociate request (or if you have access to the SQL box, direct insertion/deletion in that table). MS has some sample code available that shows how to do this using the REST Endpoint.