Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7161365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:33:17+00:00 2026-05-28T13:33:17+00:00

List<MyModel1> myModel1 = new List<MyModel1>(); MyUserModel myUserModel = new MyUserModel(); List<MyModel2> myModel2 = new

  • 0
List<MyModel1> myModel1 = new List<MyModel1>();                    
MyUserModel myUserModel =  new MyUserModel();                    
List<MyModel2> myModel2 = new List<MyModel1>();
myModel1 = m_Service1.GetMyModelFields();
myUserModel = m_Service2.GetMyUserDetails();
myModel2 = (from myModel1Field in myModel1                        
             select new MyModel2 { FieldCaption = myModel1Field.FieldAlias, 
             FieldValue = "" }).ToList<MyModel2>();

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”

One way to get the column attribute(Name) value of for a property is as below when I know the Property name.

myUserModel.GetType().GetProperty("FirstName").GetCustomAttributes(typeof(System.Data.Linq.Mapping.ColumnAttribute), false).Cast<System.Data.Linq.Mapping.ColumnAttribute>().Single().Name

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.

MyUserModel with one of it’s properties

public class MyUserModel { 
[Column(Name = "first_name", DbType = "varchar")] 
public string FirstName { get; set; } 
}

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”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:33:17+00:00Added an answer on May 28, 2026 at 1:33 pm

    If you want to get the value of a property and you only know the Name property of one of the ColumnAttribute attributes on it what you can do is this:

    // Let's say you have the user model like so:
    MyUserModel myUserModel = new MyUserModel { FirstName = "A", LastName = "B"};
    
    // And then you want the value of the property that has the Column attribute Name "first_name"
    string searchName = "first_name";    
    
    // Using some lambda you can do this (I do not know how to do this in LINQ syntax, sorry)
    object propertyValue = typeof (MyUserModel).GetProperties()
                .Where(p =>
                           {
                               var attrib = (ColumnAttribute)p
                                   .GetCustomAttributes(typeof (ColumnAttribute), false)
                                   .SingleOrDefault();
                               return (attrib != null && 
                                       attrib.Name.Equals(searchName));
                           })
                .Select(p => p.GetValue(myUserModel, null))
                .FirstOrDefault();
    
    if(propertyValue != null)
    {
        // Do whatever you want with the string "A" here - I suggest casting it to string! :-)
    }
    

    Is that what you want?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

List<DateTime> list = new List<DateTime>(); Currently i have the following syntax: if(list[list.Count - 1]
List<String> nameList = new List<String>(); DropDownList ddl = new DropDownList(); List is populated here,
List<tinyClass> ids = new List<tinyClass(); ids.Add(new tinyClass(1, 2)); bool b = ids.IndexOf(new tinyClass(1, 2))
List<SelectListItem> items = new List<SelectListItem>(); if (a) { SelectListItem deliveryItem = new SelectListItem() {
List<CertMail> lsRecipetNumber = new List<CertMail>(); CertMail class is in data access layer which returns
List<MyClass> myclassList = (List<MyClass>) rs.get(); TreeSet<MyClass> myclassSet = new TreeSet<MyClass>(myclassList); I don't understand why
I'm new to iPhone dev. My app is dynamically creating buttons, following from my
I've set up a simple form. A ListBox takes values from a list in
List<String> flowers = new ArrayList<String>(); My for loop currently looks like this... for (int
List<MyParentClass> parents = new List<MyParentClass>(); var parent1 = new MyParentClass(parent1); var parent2 = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.