i try to get name by id. I have this model. public class Category() {   public int Id { get; set; }   public string Name { get; set; }   public int ParentId { get; set; } }  I want to see the id, the category name, and the subcategory name relative to parentId in the view, but I don't know how to do it.
123190
I have a List&lt;int&gt; and a List&lt;customObject&gt;. The customObject class has an ID property. How can I get a List&lt;customObject&gt; containing only the objects where the ID property is in the List&lt;int&gt; using LINQ?  Edit: I accepted Konrads answer because it is easier/more intuitive to read.
35156
I have an XDocument object. I want to query for elements with a particular name at any depth using LINQ. When I use Descendants(&quot;element_name&quot;), I only get elements that are direct children of the current level. I'm looking for the equivalent of &quot;//element_name&quot; in XPath...should I just use XPath, or is there a way to do it using LINQ methods?
76549
For example  Drupal\Core\Entity\Entity::id() returns $this-&gt;id(or NULL) Drupal\Core\Entity\ContentEntityBase::id() returns $this-&gt;id-&gt;value Drupal\Core\Entity\ContentEntityBase::uuid() returns $this-&gt;get('uuid')-&gt;value Drupal\node\Entity\Node::id() returns $this-&gt;get('nid')-&gt;value  Also in some methods there are setValue() and getValue() utilised but sometimes there are just $this-&gt;field-&gt;value. So what is the reason for this inconsistent behavior? From my understanding all the &quot;fields&quot; are TypedData fields hence the setValue() and getValue() methods should be used instead of directly access $this-&gt;field-&gt;value. Besides it's strange because $value is private.
117135
I'm currently using Eclipselink, but I know now days most JPA implementations have been pretty standardized. Is there a native way to map a JPA entity to a view? I am not looking to insert/update, but the question is really how to handle the @Id annotation. Every entity in the JPA world must have an ID field, but many of the views I have created do not conform to this. Is there native support for this in the JPA or do I need to use hacks to get it to work? I've searched a lot and found very little information about doing this.
104723
I use an anonymous object to pass my Html Attributes to some helper methods. If the consumer didn't add an ID attribute, I want to add it in my helper method.  How can I add an attribute to this anonymous object?
48244
I have a table with a hierarchy ( with a recursive parentID column), for one record, I know how to get the last parent record, with the following code :  declare @Id integer  ;WITH CTE AS (     SELECT  a.[Id],             a.[ParentId]     FROM    [Area] a WITH (NOLOCK)     where a.[Id] = @Id       UNION ALL      SELECT  a.[Id],             a.[ParentId]     FROM [Area] a WITH (NOLOCK)     INNER JOIN CTE cte ON cte.[ParentId] = a.[Id] )  SELECT top 1 a.[Id] FROM CTE a WHERE a.ParentId is null   It works as long as I'm working with one id, here @Id.  But I can't find a way to do the same but for a list of Ids, without using cursors, as CTE seems to be OK only when y'oure working on one record.  Could someone point me at the right direction ?  Many thanks
44919
I'm trying to use Linq to return a list of ids given a list of objects where the id is a property. I'd like to be able to do this without looping through each object and pulling out the unique ids that I find.  I have a list of objects of type MyClass and one of the properties of this class is an ID.  public class MyClass {   public int ID { get; set; } }   What I want to do is write a Linq query to return me a list of those Ids  How do I do that given an IList&lt;MyClass&gt; such that it returns an IEnumerable&lt;int&gt; of the ids?  I'm sure it must be possible to do it in one or two lines using Linq rather than looping through each item in the MyClass list and adding the unique values into a list.  Any help in creating an elegant solution would be much appreciated!
81977
I'm having trouble understanding how to access each individual result returned from a subquery. The picture shows the code which:   takes fields and objects chosen by a user and assigns them to String variables, the string vars are used to query a dynamic query string, the query string is feed into a database.query and the result is stored in an array I can individually access each of the query results from this array (parent object results),  But I have not been able to individually access the subquery results.   If I feed the subquery results into an array...something like:  SObject[] c = p.get(i).getSObjects(childO);   I still can't get to each individual child record per parent. I can only see all child records per each parent. I need to get to each child record per adult, so that I can roll up results.  Can anyone help?  // These strings will be populated dynamically from a VF page String parentO  = 'Account'; String parentF  = 'Products_Purchased__c'; String childO   = 'Opportunity';     if(childO  == 'Opportunity'){ childO = 'Opportunities'; } String childF   = 'Product_Type__c';  // create dynamic SOQL query string String query = 'SELECT id, (select ' +childF+ ' from ' +childO+') FROM ' +parentO;  // query and store 33 results in variable p SObject[] p = Database.query(query);  for(Integer i = 0; i &lt; p.size(); i++){     system.debug('Parent result from SOQL query: ' +p[i]);     if(p.get(i).getSObjects(childO) &lt;&gt; null){         system.debug('Child result(s) from SOQL query: ' +p.get(i).getSObjects(childO));         system.debug('Child field: ' +c.get(i).get(childF));     } }
29862
So what I have right now is something like this:  PropertyInfo[] info = obj.GetType().GetProperties(BindingFlags.Public);   where obj is some object.  The problem is some of the properties I want aren't in obj.GetType() they're in one of the base classes further up.  If I stop the debugger and look at obj, the I have to dig through a few "base" entries to see the properties I want to get at.  Is there some binding flag I can set to have it return those or do I have to recursively dig through the Type.BaseType hierarchy and do GetProperties on all of them?
58870
When i have a relation between two entities in my model:  [GroupMember] (*) ----- (1) [User]  and tries to select items from this relation with LINQ:  From entity in _user.GroupMember select entity  I always get an empty result unless I load the relation first with following statement:  _user.GroupMember.Load()  Is there a way to avoid loading the relations like this?
26112
Given this class  class Foo {     // Want to find _bar with reflection     [SomeAttribute]     private string _bar;      public string BigBar     {         get { return this._bar; }     } }   I want to find the private item _bar that I will mark with a attribute.  Is that possible?    I have done this with properties where I have looked for an attribute, but never a private member field.  What are the binding flags that I need to set to get the private fields?
7311
I want to get Developer Name of record Type without using SOQL query.  With the below code, I'm able to get the "Name", but I want the DeveloperName.  Let me know.  string recordTypeName = Schema.SObjectType.Account.getRecordTypeInfosById().get(Account.RecordTypeId).getName();
38310
Given the following classes and controller action method:  public School {   public Int32 ID { get; set; }   publig String Name { get; set; }   public Address Address { get; set; } }  public class Address {   public string Street1 { get; set; }   public string City { get; set; }   public String ZipCode { get; set; }   public String State { get; set; }   public String Country { get; set; } }  [Authorize(Roles = "SchoolEditor")] [AcceptVerbs(HttpVerbs.Post)] public SchoolResponse Edit(Int32 id, FormCollection form) {   School school = GetSchoolFromRepository(id);    UpdateModel(school, form);    return new SchoolResponse() { School = school }; }   And the following form:  &lt;form method="post"&gt;   School: &lt;%= Html.TextBox("Name") %&gt;&lt;br /&gt;   Street: &lt;%= Html.TextBox("Address.Street") %&gt;&lt;br /&gt;   City:  &lt;%= Html.TextBox("Address.City") %&gt;&lt;br /&gt;   Zip Code: &lt;%= Html.TextBox("Address.ZipCode") %&gt;&lt;br /&gt;   Sate: &lt;select id="Address.State"&gt;&lt;/select&gt;&lt;br /&gt;   Country: &lt;select id="Address.Country"&gt;&lt;/select&gt;&lt;br /&gt; &lt;/form&gt;   I am able to update both the School instance and the Address member of the school.  This is quite nice!  Thank you ASP.NET MVC team!  However, how do I use jQuery to select the drop down list so that I can pre-fill it?  I realize that I could do this server side but there will be other dynamic elements on the page that affect the list.  The following is what I have so far, and it does not work as the selectors don't seem to match the IDs:  $(function() {   $.getJSON("/Location/GetCountryList", null, function(data) {     $("#Address.Country").fillSelect(data);   });   $("#Address.Country").change(function() {     $.getJSON("/Location/GetRegionsForCountry", { country: $(this).val() }, function(data) {       $("#Address.State").fillSelect(data);     });   }); });
35183
I'm pulling items out of the DOM with jQuery and want to set a property on an object using the id of the DOM element.   Example  const obj = {}  jQuery(itemsFromDom).each(function() {   const element = jQuery(this)   const name = element.attr('id')   const value = element.attr('value')    // Here is the problem   obj.name = value })   If itemsFromDom includes an element with an id of "myId", I want obj to have a property named "myId". The above gives me name.  How do I name a property of an object using a variable using JavaScript?
103863
I'm trying to get the ID of a lookup field when using search api. My query looks something like this:  /_api/Search/query?querytext='ListId:12345678-1234-1234-1234-123456789012'&amp;selectproperties='Title,Company'   Where Company is the lookup field, in a specific list.  The result looks like this:  &lt;d:element m:type="SP.KeyValue"&gt;   &lt;d:Key&gt;Company&lt;/d:Key&gt;   &lt;d:Value&gt;Some company&lt;/d:Value&gt;   &lt;d:ValueType&gt;Edm.String&lt;/d:ValueType&gt; &lt;/d:element&gt;   I have created a managed property which looks like this:
82389
I have a contact in a generic sObject in apex and while I'm able to easily get detail field values using   sObject.get('MyContactField__c')  I'm not able to get fields off the related parent object, and I'm sure the related field is in memory, based on the debug logs. This returns a runtime error:  sObject.get('Account.MyAccountField__c')  with the error     Invalid field Account.MyAccountField__c' for Contact   How do I get a field value off of a parent on a generic sObject?
3180
If I have a custom controller and a custom visualforce page, and I'm passing an ID as a query param, how can I get the associated record for that ID from within the VF page?  public class MyCustomController() {   ... legacy code here }  &lt;apex:page controller="MyCustomController"&gt;   &lt;apex:outputText value="{! SOME VF SYNTAX TO RETRIEVE RECORD GIVEN QUERY PARAM ID}" /&gt; &lt;/apex:page&gt;