Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Simplest syntax of converting List of one type to another
Message
 
 
To
All
General information
Forum:
C#
Category:
LINQ
Title:
Simplest syntax of converting List of one type to another
Miscellaneous
Thread ID:
01656603
Message ID:
01656603
Views:
34
Hi everybody,

I have a variable items which is List of ItemsList and I want to convert it to List of IGlink . These two classes have similar definitions with some slight differences.


This is IGlink class:
public int IglinkId { get; set; } // iglink_id (Primary key)
        public int IGroupNo { get; set; } // i_group_no. FK to i_group
        public string Department { get; set; } // department (length: 10). FK to items
        public string Category { get; set; } // category (length: 10)
        public string Item { get; set; } // item (length: 10)

        // Foreign keys
        public virtual IGroup IGroup { get; set; } // FK_i_glink_i_group
        public virtual Items Items { get; set; } // FK_i_glink_items
This is ItemsList class:
public string Department { get; set; } // Department (length: 10)
        public string Category { get; set; } // Category (length: 10)
        public string Item { get; set; } // Item (length: 10)
        public int DepartmeId { get; set; } // DepartmeId
        public int CategoryId { get; set; } // CategoryId
        public int ItemId { get; set; } // ItemId
        public string Descrip { get; set; } // Descrip (length: 135)
        public bool Hidden { get; set; } // Hidden
So, I am only interested of using ItemId, Category, Department, Item properties.

How can I quickly convert one into another? Using select new ?

Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Next
Reply
Map
View

Click here to load this message in the networking platform