none
Conditional include RRS feed

  • Question

  • I found a few references to putting conditions on the include of a query which point out workarounds like here and here but for some reason my attempts fail. My goal is to return only the active children records. The parent entity is a MappingRecord. To filter by user I started with this:

            'returns all records including assignments that are not active
            Dim results = From x In _context.MappingRecordList.Include("ServiceLines") _
                    .Include("Capabilities") _
                    .Include("Clients") _
                    .Include("Assignments")
            Where (x.AppUserID = userid)
            Select x
            Return results.FirstOrDefault

    To use the examples in the link I tried these and they also return inactive Assignments.

            'for some reason this didn't work - all assignments were returned
            'http://blogs.msdn.com/b/alexj/archive/2009/10/13/tip-37-how-to-do-a-conditional-include.aspx
            Dim results = From maprec In _context.MappingRecordList
                Where (maprec.AppUserID = userid)
                              Select New With {
                                    maprec,
                                    .assignrecs = From assign In maprec.Assignments
                                        Where assign.IsActive = True
                                        Select assign
                                    }
            Dim maps = results.AsEnumerable().Select(Function(x) x.maprec)
            Return maps.FirstOrDefault
            'http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/0877f2f3-32d4-43cd-bd13-90e6c2840e34
            'http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/6d098e7f-d556-4578-a627-eab12070a019
            Dim assigns = From x In _context.AssignmentMappingList
                          Where x.IsActive = True And x.AppUserID = userid
                          Select x
            Dim assignlist = assigns.ToList
            Dim maps = (From x In _context.MappingRecordList
                       Where x.Assignments.Any(Function(y) y.IsActive = True) And x.AppUserID = userid
                       Select x).First
            Return maps

    Is my syntax off or maybe an easier way?
    Wednesday, June 6, 2012 9:27 PM

Answers

  • Hi pretzelb,

    Yes, discussion has off-topic now. The root cuase isn't the property is virtual or not, please refer to this code, which you posted before:

    var dbquery =
                        from emp in context.EmpDetails
                        where emp.EmpID == "abc123"
                        select new
                        {
                            emp,
                            prods = from pl in emp.ProductLines
                                    where pl.ProductLine.IsActive == true
                                    select pl
                        };
                    var elist = dbquery
                        .AsEnumerable()
                        .Select(z => z.emp);
                    foreach (var e in elist)
                    {
                        foreach (var pl in e.ProductLines)
                        {
                            Console.WriteLine(e.EmpName + " " + pl.IsActive + " " + pl.Allocation);
                        }
                    }

    There's an unnecessary step in this code, and the unexpected result is caused by this step.

    Afer the 'dbquery' executing, the expected result is queried out, 'elist' is not necessary. Please refer to the code below.

    var dbquery =
                        from emp in context.EmpDetails
                        where emp.EmpID == "abc123"
                        select new
                        {
                            emp,
                            prods = from pl in emp.ProductLines
                                    where pl.ProductLine.IsActive == true
                                    select pl
                        };
              
                    foreach (var e in dbquery)
                    {
                        foreach (var pl in e.prods)
                        {
                            Console.WriteLine(e.emp.EmpName + " " + pl.IsActive + " " + pl.Allocation);
                        }
                    }

    This will return you the expected result.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by pretzelb Wednesday, June 27, 2012 12:24 PM
    Monday, June 25, 2012 8:58 AM
    Moderator

All replies

  • Hi pretzelb,

    Welcome to MSDN Forum.

    I'm afraind I'm not familar with VB.NET, I write the code in C#, please refer to it and let me know whether it is worked.

    var query = (from x in context.MappingRecordList where(x=>x.AppUserID = userid)
    			select new {
    			x,
    			assignlist = from a in context.Assignments where(x=>x.IsActive=true) select a
    			}).ToList();
    
    var maps = from x in query select x.x;

    Best Regards

    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, June 7, 2012 5:28 AM
    Moderator
  • Thanks Allen. In my first example I did try something similar to what you suggested and the filter for active still does not work. At times like this I do wish we used C#.

    I tweaked my original query a bit but it still returns both active and inactive. Either my syntax is off or there is something I'm doing in another area that is affecting this.

            Dim results = (From maprec In _context.MappingRecordList
                Where (maprec.AppUserID = userid)
                              Select New With {
                                    maprec,
                                    .assignrecs = From assign In maprec.Assignments
                                        Where maprec.Assignments.Any(Function(y) y.IsActive = True)
                                        Select assign
                                    }).ToList
            Dim maps = From x In results Select x.maprec
            Return maps.FirstOrDefault

    Thursday, June 7, 2012 1:23 PM
  • Hi pretzelb,

    Could you please use SQL Server Profiler to track the generated T-SQL? Try to check whether it is what you want.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, June 7, 2012 2:31 PM
    Moderator
  • Great idea.  I ran the Profiler against this:

            Dim query = (From x In _context.MappingRecordList
                         Where (x.AppUserID = userid)
                         Select New With { _
                             x, _
                             Key .assignlist = From a In x.Assignments
                                               Where (a.IsActive = True)
                                               Select a _
                                            }
                        ).ToList()
            Dim maps = From x In query Select x.x
            Return maps.FirstOrDefault

    When the above is run in SSMS it appears to do what I expect. Only the active records are returned.

    However there is no change in the results in WPF code. If I break right after this call is finished and view the MappingRecordList object returned I show a collection of Assignments that include in-active records. Very strange. The LINQ code is in simple procedure named GetUserMappingRecord that is called from a view model like so:

    UserMappingRecord = _mappingRepository.GetUserMappingRecord(SelectedUser.ID)



    • Edited by pretzelb Friday, June 8, 2012 8:57 PM
    Friday, June 8, 2012 8:54 PM
  • Hi pretzelb,

    Could you please upload a demo to SkyDrive and post the link here? I will download it and help you to test it.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, June 11, 2012 3:15 AM
    Moderator
  • I'm not sure if uploading the solution would help since I don't have any test data to share. I can look into creating a demo project with it's own data and uploading that.

    Could this be caused by the configuration of the entity data model? We are working off a closed DB that we cannot alter so I tried my best to craft useful group of entity models. Assignments have a relationship with MappingRecordList via the AppUserId field but they also have a relationship to the Clients collection. Query analyzer indicates that the filter logic in the LINQ is correct but the results still show all the Assignments. Could a flaw in the model design cause that?

    Monday, June 11, 2012 6:19 PM
  • Hi pretzelb,

    The query is not complex, so I think the wrong data may not caused by the query statement. I suggest you to have a test in two steps query, don't use nested query, and to check whether the result is correct. First, query out all the records which 'IsActive' is true from 'Assignments'. Second, using 'Contains' method to filter the 'MappingRecordList''s navigation property.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, June 12, 2012 6:28 AM
    Moderator
  • I managed to convert the last demo I uploaded to display this behavior. It's not the exact same code but using the same syntax for the query gives the same results. I attempt to filter out for only active = true and I get all. Hopefully it's a good example of the issue. The solution is in skydrive and should be ready to run. There is a lot of extra code for testing other things so please ignore the other items.
    Tuesday, June 12, 2012 1:58 PM
  • Hi pretzelb,

    I have downloaded the project. I'm sure the query statement is correct, and if you only create a small demo to do such a query, it would work well. You've looked the generated T-SQL by the query in SQL Server Profiler, it returns the expected records. Since I'm not familar with WPF and VB.NET, I suggest you to track the code from starting, try to press 'F11' to debug step by step. Checking is there any event is fired when loading the data, it may affect the result. If you need further help, please feel free to let me know.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, June 14, 2012 6:22 AM
    Moderator
  • I've converted the employee demo app I created to C# (located here on skydrive) and I tried to mimic your syntax for the conditional include. This time I just did a simple console app and sent the results to the screen. It still seems to ignore the conditional include. I may have made an error on the conversion to C# but hopefully it's easier for you to spot the issue now.
    Friday, June 15, 2012 3:18 PM
  • Hi pretzelb,

    I have downloaded the project and will test it as soon as possible. :)

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, June 18, 2012 2:45 AM
    Moderator
  • Hi pretzelb,

    I have tested the code, the query result is the expected one, I didn't change any code in your demo.

    Please look at the records in the database, the forum only support upload two pictures per reply, so I will represent the records in two replies.

    In the 'EmpDetailMasters' table, the records as below.

    In the 'ProductLineAllocs' table, the records as below.

    Please continue to look at the next reply.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, June 18, 2012 6:53 AM
    Moderator
  • In the 'ProductLines' table, the records as below.

    The query result as below.

    the active product's 'ProductLineID' are 1,2,3, in the 'ProductLineAlloc' table, the records' 'ProductLineAllocID' are 1,4,5. But the last two records' 'EmpID' are not 'abc123', so the expected record is the first record of this table. Please look at the result of the query, it appears the correct result. Please check your database tables' records, I think the incorrect results may caused by the database.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, June 18, 2012 7:00 AM
    Moderator
  • Maybe we have a disconnect on what to expect on the results. Here is a screen print of what I get when I run the code below. My expectation was that emps.First().ProductLines would only have isActive of True.

    Are your console results different?

                    var query = (from x in context.EmpDetails.Where(y => y.EmpID == "abc123")
                                 select new
                                 {
                                     x,
                                     prodlines = from a in x.ProductLines.Where(b => b.ProductLine.IsActive == true) select a
                                 }).ToList();
                    var emps = from x in query select x.x;
                    ObjectDumper.Write(emps.First().ProductLines);
                    Console.WriteLine("Press any key to continue...");
                    Console.ReadKey(true);

    Monday, June 18, 2012 12:38 PM
  • Hi pretzelb,

    The query has no problem, the root cause of printing such result is the parameter of 'ObjectDumper.Write' method, you have queried out the expected 'EmpDetailMasters' result as what I post in the previous reply, but when printing out, this statement 'emps.First().ProductLines' queried all the ProductLines against the emps. So the 3 records appears. Please refer to the code below.

     class Program
        {
            static void Main(string[] args)
            {
                using (var context = new EmpMapContext())
                {
    
    
                    var query = (from x in context.EmpDetails.Where(y => y.EmpID == "abc123")
                                 select new
                                 {
                                     x,
                                     prodlines = from a in x.ProductLines.Where(b => b.ProductLine.IsActive == true) select a
                                 }).ToList();
    
                    foreach (var v in query)
                    {
                        foreach (var vv in v.prodlines)
                        {
                            Console.WriteLine(v.x.EmpName + vv.EmpID);
                        }
                    }                
                    //ObjectDumper.Write(emps);
                    //ObjectDumper.Write(emps.First().Clients);
                    
                    Console.WriteLine("Press any key to continue...");
                    Console.ReadKey(true);
    
                }
            }
        }

    Best Regards

    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, June 19, 2012 4:52 AM
    Moderator
  • Sorry about that. Really dumb mistake on my part.

    However I think I have found the root cause of the problem. My expectation might be wrong on what should happen. If I run this code I will see the active and inactive records:

    var query = (from x in context.EmpDetails.Where(y => y.EmpID == "abc123")
                    select new
                    {
                        x,
                        prodlines = from a in x.ProductLines.Where(b => b.ProductLine.IsActive == true) select a
                    }).ToList();
    var emps = from x in query select x.x;
    Console.WriteLine("query.prodlines");
    foreach (var v in query)
    {
        foreach (var vv in v.prodlines)
        {
            Console.WriteLine("  " + v.x.EmpName + " " +  vv.EmpID + " " + vv.Allocation + " " + vv.IsActive);
        }
    }
    Console.WriteLine(" ");
    Console.WriteLine("EmpDetails.ProductLines");
    foreach (var y in emps)
    {
        foreach (var yy in y.ProductLines)
        {
            Console.WriteLine("  " + y.EmpName + " " + yy.Allocation + " " + yy.IsActive );
        }
    }
    Console.WriteLine("Press any key to continue...");
    Console.ReadKey(true);

    I had hoped that they conditional include would affect the EmpDetails collection but instead all we are doing is creating a new entity that contains all the original children record of EmpDetails plus a collection of ProductLines that is filtered.

    I went back and looked at this article on how to do a conditional include and I believe this is why I assumed it would work the way I expected. I created some code to match the sample as closely as possible but the results are still not what I (incorrectly?) expected. The one difference I can see is that in the sample the "Stars" filter is on the child class "Review" where my "IsActive" is not a property of "ProductLineAlloc" but instead part of the navigation property "ProductLine". The key might be me understanding what the author means by:

    This works because EF implements something called relationship fix-up.

    Relationship fix-up ensures that related objects are automatically linked when the second entity enters the ObjectContext.

    I might need to also try a quick demo using the code provided by the author.

                    var dbquery =
                        from emp in context.EmpDetails
                        where emp.EmpID == "abc123"
                        select new
                        {
                            emp,
                            prods = from pl in emp.ProductLines
                                    where pl.ProductLine.IsActive == true
                                    select pl
                        };
                    var elist = dbquery
                        .AsEnumerable()
                        .Select(z => z.emp);
                    foreach (var e in elist)
                    {
                        foreach (var pl in e.ProductLines)
                        {
                            Console.WriteLine(e.EmpName + " " + pl.IsActive + " " + pl.Allocation);
                        }
                    }


     

    • Edited by pretzelb Tuesday, June 19, 2012 7:49 PM
    Tuesday, June 19, 2012 6:32 PM
  • Hi pretzelb,

    The code you posted also will return all the 'IsActive' and not 'IsActive'.

    The 'elist' you queried out is a list of EmpDetails, it isn't related to ProductLineAlloc, so when you loop the collection and call the element's navigation property, it will also return all the related entities without filter. The filter result only exist in the 'dbquery'.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, June 20, 2012 9:06 AM
    Moderator
  • It sounds like I'm assuming something on the entity definition that isn't true.

    The "elist" I queried is out of dbquery (var elist = dbquery ...). Also, EmpDetails is a DbSet of type EmpDetailMaster which has a navigation property ProductLines that is an ObservableCollection of ProductLineAlloc. I had thought this was similar as the definition of Movies which is a DbSet of type Movie that has a navigation property named Reviews which is a List of Review objects.

    Here is a working sample of the Movie object from the link I previously mentioned. The conditional include section seems identical but hte results are different from what I see with the EmpDetails sample.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.Entity;
    using System.Data.Entity.ModelConfiguration;
    using System.Collections.ObjectModel;
    using System.Data.Entity.Validation;
    namespace EmpMapDemo_Console
    {
        class MovieDemo
        {
            static void Main(string[] args)
            {
                Database.SetInitializer(new MovieContextInitializer());
                using (var ctx = new MovieContext())
                {
                    var dbquery = from movie in ctx.Movies 
                                  where movie.Genre == "Horror"
                                    select new { 
                                        movie,  
                                        reviews = from review in movie.Reviews 
                                    where review.Stars == 5 
                                select review 
                                    };
                    var movies = dbquery 
                       .AsEnumerable() 
                       .Select(m => m.movie);
                    foreach (var x in movies)
                    {
                        Console.WriteLine("Movie - id=" + x.ID + " name=" + x.Name + " genre=" + x.Genre );
                        if (x.Reviews != null)
                        {
                            foreach (var y in x.Reviews)
                            {
                                Console.WriteLine("   stars=" + y.Stars);
                            }
                        }
                    }
                    Console.WriteLine("Press any key to continue...");
                    Console.ReadKey(true);
                }
           }
        }
        public class MovieContextInitializer : DropCreateDatabaseAlways<MovieContext>
        {
            protected override void Seed(MovieContext context)
            {
                var r1s = new List<Review> 
                    {
                        new Review { ID= 1, Stars = 1, Summary="abc"},
                        new Review { ID= 2, Stars = 5, Summary="abc"},
                        new Review { ID= 3, Stars = 5, Summary="abc"}
                    };
                var r2s = new List<Review> 
                    {
                        new Review { ID= 4, Stars = 5, Summary="abc"},
                        new Review { ID= 5, Stars = 2, Summary="abc"}
                    };
                var r3s = new List<Review> 
                    {
                        new Review { ID= 6, Stars = 4, Summary="abc"}
                    };
                var r4s = new List<Review> 
                    {
                        new Review { ID= 7, Stars = 5, Summary="abc"},
                        new Review { ID= 8, Stars = 5, Summary="abc"}
                    };
                var m1 = new Movie { ID = 1, Genre = "Horror", Name = "Horror1", Reviews = r1s };
                var m2 = new Movie { ID = 2, Genre = "Horror", Name = "Horror2", Reviews = r2s };
                var m3 = new Movie { ID = 3, Genre = "Horror", Name = "Horror3", Reviews = r3s };
                var m4 = new Movie { ID = 4, Genre = "Romance", Name = "Romance1", Reviews = r4s };
                context.Movies.Add(m1);
                context.Movies.Add(m2);
                context.Movies.Add(m3);
                context.Movies.Add(m4);
                IEnumerable<DbEntityValidationResult> _vr = null;
                _vr = context.GetValidationErrors();
                foreach (DbEntityValidationResult entvalidationresult in _vr)
                {
                    foreach (DbValidationError ve in entvalidationresult.ValidationErrors)
                    {
                        string s1 = ve.PropertyName;
                        string s2 = ve.ErrorMessage;
                    }
                }
                context.SaveChanges();
            }
        }
        public class MovieContext : DbContext
        {
            public DbSet<Movie> Movies { get; set; }
            public DbSet<Review> Reviews { get; set; }
            protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
            {
            }
        }
        public class Movie
        {
            public int ID { get; set; }
            public string Name { get; set; }
            public string Genre { get; set; }
            public List<Review> Reviews { get; set; }
        }
        public class Review
        {
            public int ID { get; set; }
            public int Stars { get; set; }
            public string Summary { get; set; }
            public Movie Movie { get; set; }
        }
    }


    • Edited by pretzelb Wednesday, June 20, 2012 1:30 PM
    Wednesday, June 20, 2012 1:27 PM
  • I think the confusion is caused by this definition:

            public virtual ObservableCollection<ProductLineAlloc> ProductLines { get; set; }

    If I remove "virtual" (which matches the Movie demo code) the result I expected is seen. The EmpDetails object correctly only contains only 1 child / related ProductLineAlloc entity who has isActive of true.

    Wednesday, June 20, 2012 3:01 PM
  • Hi pretzelb,

    If the 'virtual' is removed, EF will not support lazy loading. That means, if you don't explicitly load related entities or using 'Include' to load related entities, you will always get an empty colletion when you try to get 'ProductLines' from an EmpDetailMaster entity. Lazy loading will make EF to hit the database everytime when you call the navigation properties, so if you removed it, EF will no hit the database, that means, when you call the navigation property, it will only include the entities which have aleady queried out and loaded in the memory. So the result is correct.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, June 21, 2012 5:23 AM
    Moderator
  • Allen

    I researched 'virtual' and lazy loading and what you stated makes sense. However, I also tried to research 'entity fix-up' to see if I could see how it is affected by lazy loading but I didn't find much. We might be veering off topic but something still doesn't seem correct. Let's refer to the MovieDemo code included a few posts ago. The key piece of code appears to be the conditional include found here:

    reviews = from review in movie.Reviews where review.Stars == 5 

    The Movie class code does not define 'virtual' so lazy loading is not supported. That means the Reviews list is empty unless specifically loaded. I assume that means that when the above code is executed movie.Reviews is loaded with a list of Review entities that meet the criteria of Stars == 5. This is handled by entity fix-up as the author of the article points out.

    If the Movie class code did define 'virtual' on the Reviews navigation property then lazy loading would be supported. That means the Reviews list would hit the DB if a call to the navigation property was made. The code above should only return the same subset of entities where Stars == 5, and it does as we saw when we queried the results. But now for some reason 'entity fix-up' is not engaged because Movie.Reviews later in the code will show the full list of Review entities not affected by the conditional include.

    Is this line of code the problem?

     foreach (var y in x.Reviews)

    Does that reference to the navigation property force lazy loading to engage and get a full list from the DB which would pretty much wipe out the filtered list we prepared for entity fix-up to use? If so then it would seem like conditional include and lazy load are mutually exclusive. As soon as the navigation property of the entity is referenced a call to the DB is made which loads all entities.

    Thursday, June 21, 2012 3:19 PM
  • Hi pretzelb,

    Yes, discussion has off-topic now. The root cuase isn't the property is virtual or not, please refer to this code, which you posted before:

    var dbquery =
                        from emp in context.EmpDetails
                        where emp.EmpID == "abc123"
                        select new
                        {
                            emp,
                            prods = from pl in emp.ProductLines
                                    where pl.ProductLine.IsActive == true
                                    select pl
                        };
                    var elist = dbquery
                        .AsEnumerable()
                        .Select(z => z.emp);
                    foreach (var e in elist)
                    {
                        foreach (var pl in e.ProductLines)
                        {
                            Console.WriteLine(e.EmpName + " " + pl.IsActive + " " + pl.Allocation);
                        }
                    }

    There's an unnecessary step in this code, and the unexpected result is caused by this step.

    Afer the 'dbquery' executing, the expected result is queried out, 'elist' is not necessary. Please refer to the code below.

    var dbquery =
                        from emp in context.EmpDetails
                        where emp.EmpID == "abc123"
                        select new
                        {
                            emp,
                            prods = from pl in emp.ProductLines
                                    where pl.ProductLine.IsActive == true
                                    select pl
                        };
              
                    foreach (var e in dbquery)
                    {
                        foreach (var pl in e.prods)
                        {
                            Console.WriteLine(e.emp.EmpName + " " + pl.IsActive + " " + pl.Allocation);
                        }
                    }

    This will return you the expected result.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by pretzelb Wednesday, June 27, 2012 12:24 PM
    Monday, June 25, 2012 8:58 AM
    Moderator
  • I agree that I can get the subset of records using the code you provided, but I am not sure that is expected behavior. The only way a conditional include can really be useful is when entity fix up works with it.

    In your code we are not looking at the ProductLineAlloc collection of the entity itself. THAT is where the conditional include needs to be in effect. The list called 'prods' is one that was created on the fly with the select statement. If this were normal code we would be returning a predefined entity type like EmpDetailMaster (or Movie) and not one we defined on the fly. Having the correct subset only available outside the definition of the entity isn't what I would expect out of this solution. I'm not sure if it's useful unless it affects the entity itself.

    If you go back and use the code I copied from the blog post it does provide the results that I would expect. The subset is included in the list of ProductLineAlloc that are part of the entity (ProductLines) by ONLY if you leave out the virtual keyword. This is what the author did in the Movie sample as well. Your code does this as well but again, ONLY if you leave out virtual. Try this small modification to the loop and watch how the count changes if you use virtual or leave it out.

    foreach (var e in dbquery)
    {
        foreach (var pl in e.prods)
        {
            Console.WriteLine(e.emp.EmpName + " " + pl.IsActive + " " + pl.Allocation);
        }
        Console.WriteLine("pl count on entity = " + e.emp.ProductLines.Count);
                        
    }

    Would it be reasonable to assume that if we were coding a typical application the expectation is our query should return a predefined entity type like Movie or EmpDetailMaster? If that assumption is true, then I think the conditional include needs to use this 'entity fix up' so that the master entity only contains the expected subset of records (Review or ProductLineAlloc) which are accessible via the navigation property on the main entity (ProductLines or Reviews). Given that assumption then the use of 'virtual' is crucial in getting this to work.

    I think if we use the code you provided in a data access layer we would need to return an instance of the main EmpDetailMaster entity and a collection of ProductLineAlloc as represented by e.prods. Also, unless you eliminate 'virtual' from the definition, this would result in collection of ProductLineAlloc inside the EmpDetailMaster entity returning the full list of 3 ProductLineAlloc entities which represents the unfiltered list associated to the entity. Any view which used this DAL would need to NOT use the navigation of EmpDetailMaster.ProductLines and instead reference the results from e.prods.

    If you'd like I can mark one of your responses as the answer and start a new topic on entity fix up. I think that might be where this is leading.

    Tuesday, June 26, 2012 1:47 AM
  • Hi pretzelb,

    OK, I think it is better to open a new thread to talk about this topic, so we can let this thread close to the original topic, and other members who encounter the similar issue can search the solution easier. I will continue to help you with the topic. :)

    Best Regards 


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, June 27, 2012 3:20 AM
    Moderator