Martin McMahon
Martin McMahon

Reputation: 333

ViewModel error

I was given some help on here recently and set up a view model called RegisterViewModel containing fields from (currently) two different models. This worked and I can use it to register a new user along with related user info. My problem is viewing the details from this same view model. In the Usee controller in my 'Details' method I have the same code -

public ViewResult Details(RegisterViewModel viewModel)
        {
            TRSContext context = new TRSContext();
            User currentuser = context.Users
                .Include(i => i.UserDetails)
                .Where(i => i.UserName == viewModel.UserName)
                .Single();

            currentuser.UserDetails = new UserDetails();

            return View(userRepository.Find(viewModel.UserName));
        } 

But I am getting the error -

Cannot convert lambda expression to type 'string' because it is not a delegate type

for the line -

(i => i.UserDetails)

Any ideas what's wrong with this?

Upvotes: 0

Views: 71

Answers (2)

James
James

Reputation: 82096

The lambda version of Include was introduced in EF CTP4, unless you have that you need to use a string i.e.

.Include("UserDetails")

Upvotes: 1

Klaus Byskov Pedersen
Klaus Byskov Pedersen

Reputation: 120917

It should be .Include("UserDetails") instead.

Upvotes: 1

Related Questions