Oguzhan Cevik
Oguzhan Cevik

Reputation: 686

'IEnumerable<object>' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'IEnumerable<object>'

I'm writing Api with Visual Studio, but I get errors.

Error 1: error 1

Error 2: error 2

Login login = new Login();
//set some properties
db.Logins.Add(login);
db.SaveChanges();

'IEnumerable' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'IEnumerable' could be found (are you missing a using directive or an assembly reference?)

And:

var user = db.Logins.Where(x => x.UserName == username && 
                                x.Password == password).FirstOrDefault();

'object' does not contain a definition for 'UserName' and no extension method 'UserName' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

Please help me.

Upvotes: 0

Views: 4252

Answers (1)

IEnumerable is an interface that contains a single method Enumerator GetEnumerator();. Which makes IEnumerable read-only.

Use ICollection to Add item in a collections.

Check if you import this namespaces:

System.Collections.Generic;

System.Linq;

Upvotes: 1

Related Questions