0

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?

ChathurawinD
  • 756
  • 1
  • 13
  • 35

1 Answers1

1

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?

Leo
  • 14,625
  • 2
  • 37
  • 55