Plugin update field from a related entity [closed] - plugins

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I want to build a plugin for updating a field from a related entity.
On Entity Agreement I have two fields: field A(look-up Account) and field B(look-up Contact)
I have to check if an option set field from Account(field A) is one specific value, then to update an option set field from Contact(field B).
That's all. Thanks!

Entity agreement = (Entity)context.InputParameters["Target"]; // this is your target entity from which plugin is firing.
// Now do whatever your check you wish to perform
// once you are ready to update lookupAccount Record below code will work
Entity lookupAccount = new Entity();
lookupAccount.LogicalName = "account";
lookupAccount.Id = agreement.GetAttributeValue<EntityReference>("field A").Id;
lookupAccount["optionSetFieldToUpdate"]= new OptionSetValue(1234);
orgService.Update(lookupAccount);
// In similar way you can perform update for ook-up Contact)
Entity lookupContact = new Entity();
lookupContact.LogicalName = "contact";
lookupContact.Id = agreement.GetAttributeValue<EntityReference>("field B").Id;
lookupContact["optionSetFieldToUpdate"]= new OptionSetValue(1234);
orgService.Update(lookupContact);

Related

How to Model data using UML for this situation? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
The Situtation is that there is a data named Progress which has 2 valid values (suppose 'A' and B). this means Progress = 'A' or Progress = B. A is just a string, but B is not string. B itself has some valid values (suppose strings: 'V1', 'V2', 'V3'). progress can be A which is a string or can be B which is 'V1', 'V2' or 'V3'. How to model this data?
If B is just a simple string (just like A) so we can define Progress as a string but i think one solution is defining progress as a class which has two children: Class A & Class B. Class B has 2 fields: Id & state so we have 3 IDs which correspond to 3 states: 'V1', 'V2' and 'V3' and Class A with a const field called state with fixed value 'A'. so with this solution progress can be objects A or B which has a state.
Please help me if such design is not good or if there is any design pattern for such situation.
First of all, since I'm not 100% sure if you speak about classes in a typed language or objects in a dynamically typed language, I'd like to clarify the obvious: UML uses typed objects. So object instances such as progress must be of a class Progress that defines their properties and behaviors.
If your question would really be only about data and values, since there is no overlap between 'A' and 'Vn', the easiest way would be to define Progress as a class with a sole property that is of type String.
But from your narrative, I understand that it's not just about data but also about semantics and potentially object behaviors:
One way to address your requirement is to use class specialisation: Progress would have a generalization set with two specializations, ProgressString (with a sole String property) and B (with itself having a string property). Moreover the generalization set would have the constraint {complete, disjoint}
Another way is to use object composition (caution do not confuse object composition with UML composition): Progress would have two properties, a String and a B (defined as above). If you'd give them a multiplicity of 0..1 you could use a constraint to make sure that it's either the one or the other but not the two.
In both cases, if you want the string to be limited to the possible values that you have documented, you'd need to add a constraint. Alternatively, you could go for a more expressive model, using an «enumeration» to make explicit the possible values (as qwerty_so suggested in the comments).

Many to Many in RESTFUL API [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
For example let's say I have employees and restaurant resources:
Employee {ID, Name, Gender, Birthday} exposed to GET\POST\PUT\DELETE
Restaurant {ID, Name, Address, Business_Number} exposed to GET\POST\PUT\DELETE
Also, I have many to many resources:
Restaurant_Has_Employee {ID, Employee_ID, Restaurant_ID, Employee_Work_In_Restaurant}
So the question is, what is the best practise to expose GET\POST\PUT\DELETE to this resource?
I always do this using the following pattern:
parents/{id}/children
In your case, if for the sake of the example a given restaurant had the id of 55, then the url GET restaurants/55/employees would a return a list of employees that belong to that restaurant, and POST restaurants/55/employees would be used for inserting a new employee to that restaurant's record. PUT isn't really relevant here, since it should be used directly on the employee endpoint, but DELETE restaurants/55/employees could be used to delete all employees belonging to that restaurant.
BTW, this looks like a duplicate of this question.
Edit: Made path nouns plural

Updating Entity Framework entity is failing because of relational Entity

I have this structure.
Question ---< Answer
-------- ------
Id Id
Text Value
I am attempting to update the value of Answer by getting it by Id from the DbContext setting the value to something new and then calling SaveChanges.
This is failing stating that question is required. I have the navigational property on Answer virtual.
For some reason EF thinks that I want the question to be null. If I set a breakpoint and lazy load the question in then it all works fine.
I only want to update the value, will I need to eager load the question?
If so this seems odd to me.
Addendum
There is a [Required] Data Annotation on Question in the Answer entity which seems to be causing the problem.
Yea, that's how it works. If your navigation property is not nullable, save will fail until you load it. You have 2 solutions:
If you have navigation property virtual Question Question { get; set; }
you should also add int QuestionID { get; set; } so when you load your Answer you will have QuestionID value set, and it means your Question can be null, because QuestionID information is enough.
If you don't have context.Entry(entityToUpdate).State = EntityState.Modified; and have context.Configuration.AutoDetectChangesEnabled = true; then when you change something on Answer the save changes will only update changed values, not the other ones, so the null property wont be a problem.

Update a composed entity in greenDao

Let say i have a business domain in which there are two entities, Survey and Question, in OOP terms, the Survey has QuestionsList, the greenDao generation getQuestions method which returns a list of questions resolving 1:M relation from Survey to Question, but there is no method like setQuestions( questionList) which will take a list of question to update. How can i update the questionList for the Survey entity ?
you can use:
getQuestions().add(Question);
but for setting Question parent you should set ParentId for your Question and then add it to QuestionList of Survey. ParentId is the foreign-key of Question which links a question to a survey.
Remember that you must store Question after these changes.

How to get id of last inserted row with ADO.NET Entity Data Model [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
getting identity row value using ADO.NET Entity
This is my example code:
var klienciToAdd = new klienci();
klienciToAdd.nazwa = collection["nazwa"];
klienciToAdd.miejscowosc = collection["miejscowosc"];
_db.AddToklienci(klienciToAdd);
_db.SaveChanges();
Just use klienciToAdd.id after calling SaveChanges() method.