I have 4 entities

Product                  no Enumerable interface
ProductFieldLookup       has Enumerable interface
Lookup                   no Enumerable interface
LookupType               has Enumerable interface


var pfl = (from pflSet in p.ProductsFieldsLookups
            where pflSet.IsAvailable = true
             select pflSet).ToList();

I want to retrieve lookups data that is connected to the returned list
and apply a filter on retrieval I think using linq seems to be most efficent
I am avoiding foreach so as to filter on retrieval of the data rather than
after retrieval.

the first way I thought to do this is by copying the structure above

var plt = (from ltset in pfl.LookupType
           where ltset.IsEditable = true && 
           ltset.IsCreatable = true
           select ltset).ToList();

the error is that pfl.LookupType does not have a defintion for lookupType

now if I use a foreach loop as follows

foreach(ProductsField pfl in p.ProductsFieldsLookups())
{

  LookupType l =  pfl.LookupType;

}

this works anyone any ideas ?

Edited 3 Years Ago by mike_2000_17: Fixed formatting

I'd need to see the object definitions for ProductFieldLookups and LookupType to really answer the question, but without seeing them it appears that pfl.LookupType isn't a collection.

You are right it isn't a colleciton

In the .edmx designer cs here is the def for ProductFieldsLookup

public global::System.Data.Objects.ObjectQuery<ProductsFieldsLookup> ProductsFieldsLookupSet
        {
            get
            {
                if ((this._ProductsFieldsLookupSet == null))
                {
                    this._ProductsFieldsLookupSet = base.CreateQuery<ProductsFieldsLookup>("[ProductsFieldsLookupSet]");
                }
                return this._ProductsFieldsLookupSet;
            }
        }
        private global::System.Data.Objects.ObjectQuery<ProductsFieldsLookup> _ProductsFieldsLookupSet;



 public global::System.Data.Objects.ObjectQuery<Lookup> LookupSet
        {
            get
            {
                if ((this._LookupSet == null))
                {
                    this._LookupSet = base.CreateQuery<Lookup>("[LookupSet]");
                }
                return this._LookupSet;
            }
        }
        private global::System.Data.Objects.ObjectQuery<Lookup> _LookupSet;

The relationships between the table are

Product ---- ProductFieldLookup
1 M

Lookup ------ LookupType
M 1

ProductFieldLookup ----- Lookup
1 M


ProductFieldLookup ----- Lookup
M 1


Its not that I dont have a solution using loops to this problem but I would
prefer to use linq if possible to make it more efficent

Edited 6 Years Ago by davidbrennan: forgot to mark code with special tag

This article has been dead for over six months. Start a new discussion instead.