Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting property value based on its column attribute value
    primarykey
    data
    text
    <pre><code>List&lt;MyModel1&gt; myModel1 = new List&lt;MyModel1&gt;(); MyUserModel myUserModel = new MyUserModel(); List&lt;MyModel2&gt; myModel2 = new List&lt;MyModel1&gt;(); myModel1 = m_Service1.GetMyModelFields(); myUserModel = m_Service2.GetMyUserDetails(); myModel2 = (from myModel1Field in myModel1 select new MyModel2 { FieldCaption = myModel1Field.FieldAlias, FieldValue = "" }).ToList&lt;MyModel2&gt;(); </code></pre> <p>myModel1Field.FieldAlias text will be same as value of one of the Column attribute of one of the property in myUserModel. So I have to search for the column atribute(Name) in myUserModel and get the corresponding property values and assign it to 'FieldValue'. If I can't find the value in myUserModel I can set 'FieldValue' as "NA"</p> <p>One way to get the column attribute(Name) value of for a property is as below when I know the Property name.</p> <pre><code>myUserModel.GetType().GetProperty("FirstName").GetCustomAttributes(typeof(System.Data.Linq.Mapping.ColumnAttribute), false).Cast&lt;System.Data.Linq.Mapping.ColumnAttribute&gt;().Single().Name </code></pre> <p>But in my case Property name will not be known. I have to find the property based on the myModel1Field.FieldAlias value. How to go about this. Please suggest.</p> <p>MyUserModel with one of it's properties</p> <pre><code>public class MyUserModel { [Column(Name = "first_name", DbType = "varchar")] public string FirstName { get; set; } } </code></pre> <hr> <p>Now if myModel1Field.FieldAlias is 'first_name' then I have to search in MyUserModel for a property with Column attribute(Name) as first_name. If it exists i have to set it's value to 'FieldValue'. Else set 'FieldValue' as "NA".</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload