简体   繁体   中英

Select list of objects using a LINQ query

I have an object list like this. Object is type of TBLM_PRODUCT this is the entity framework generated class for my database table TBLM_PRODUCT. My TBLM_PRODUCT class looks like this

public partial class TBLM_PRODUCT
    {
        public string PRODUCT_CODE { get; set; }
        public string PRODUCT_DESC { get; set; }
        public string PRODUCT_ISBN { get; set; }
        public string PRODUCT_SUPPLIER { get; set; }
        public string PRODUCT_PROGROUP { get; set; }
        public string PRODUCT_MEDIUM { get; set; }
        public Nullable<decimal> PRODUCT_ACTIVE { get; set; }

    }

I have declared my list like this. private IEnumerable myList= new List();

I'm getting objects to list like this

myList = RAEntity.TBLM_PRODUCT.ToList<DataControllers.TBLM_PRODUCT>();

I want to query this list to get items which are active. In a normal sql query I can do it like this.

select * from TBLM_PRODUCT where PRODUCT_ACTIVE = 1;

I need to select a list of objects. How can achieve it using a LINQ query?

This...

RAEntity.TBLM_PRODUCT
    .Where(x => x.PRODUCT_ACTIVE == 1)
    .ToList<DataControllers.TBLM_PRODUCT>();

will be translated by EF to...

select * from TABLE where Active = 1

Just make sure the Where extensions is called before to List . However, I'm just a bit puzzled as to why the PRODUCT_ACTIVE data type is decimal ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM