On Thu, 2010-06-24 at 14:53 -0400, Abe Gillespie wrote:
> I'll be the first to admit I'm no Linq genius (hardly), but I'm
> thinking the deferred execution of the whole thing ultimately has the
> "new" op showing up in the where clause.  If I have this right it's
> essentially doing the following query:
> 
> var me = from u in _db.Users
>               where u.Status == "active" && new User(u).Name == "Abe"
>               select new User(u);
> 
> Don't worry, I'm using DI to send the database context into the
> constructor.  I just threw the example together ... not even sure if
> it would compile.

Trying to get something that (1) compiles, and (2) actually hits the
error you're encountering would be extremely helpful so that we're (1)
on the same page wrt where the bug lies, and (2) can sanely discuss
workarounds. :-)

To the best of my knowledge, this:

        userRepo.GetAll().Where(u => u.Name == "abe")

should NOT result in creation of anything within the .Where()
expression.

For good measure, in order to better mimic what I *think* you're
attempting to do, I wrote this:

        class E {
            public int ID;
            public string Name;
        }

        [Test]
        public void TESTME()
        {
            Northwind db = CreateDB();
            var nancy = GetEmployees (db).Where (e =>
                    e.Name == "Nancy Davolio")
                .SingleOrDefault ();
            Console.WriteLine (nancy.Name);
        }

        static IQueryable<E> GetEmployees(Northwind db)
        {
            return from e in db.Employees
                where e.Region == "WA"
                select new E {
                    ID    = (int) e.EmployeeID, 
                    Name  = e.FirstName + " " + e.LastName,
                };
        }

I believe this is vaguely close to what you did, in that we're taking
the database types (Employee), selecting them into a user type (E), and
then further querying that to select a specific entry ("nancy").

This works as is, no exceptions generated.

I would appreciate it if you could provide a compiling, valid, FAILING
sample UNLESS the compiling+failing sample is close to my previous
sample which has an explicit 'new' within the 'where'.

Thanks,

 - Jon


-- 
You received this message because you are subscribed to the Google Groups 
"DbLinq" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/dblinq?hl=en.

Reply via email to