1

I used to have a straight up controller returning a view like this

return View(db.Stuff.ToList()); 

This works fine. I started laborating a bit and found that this:

var items = from g in db.Stuff
            select g;
return View(items);

...also works fine. However, as I try to join with another table :

var items = from g in db.Stuff
            join ug in db.OtherStuff on g.Id equals ug.StuffId
            where !ug.UserId.Equals(1)
            select g;
return View(items);

I get an error in the view saying:

Unable to create a constant value of type 'System.Object'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.

Why is this? Another odd thing is that if I comment out the where clause, it seams to work again (work as in not throw an exception)

2
  • What is the type of OtherStuff.UserId? Commented Jul 28, 2011 at 16:52
  • Well, its a Guid/uniqueidentifier. I edited the question so it's alitlle bit less wierd... Commented Jul 28, 2011 at 16:54

1 Answer 1

3

Try changing your where clause to this:

where ug.UserId != 1
Sign up to request clarification or add additional context in comments.

1 Comment

Hm, well actually the userId is a Guid. I was not thinking that would make any diffrence... sorry about that. where ug.UserId != new Guid() works fine. However what I'm ultimatly am trying to achieve is to match Membership.GetUser().ProviderUserKey and when I put where ug.UserId = mu.ProviderUserKey I do get the original error again... edit: putting the ProviderUserKey in a Guid-variable first works tho. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.