Reputation: 1032
I am having difficulties on getting my insert method to work correctly. I am new to back end development so any suggestions or comments will be helpful.
public Boolean insertDefaultUser()
{
Boolean flag = true;
Users newUser = new Users();
newUser.alias = "bulby";
newUser.password = "chicken";
newUser.email = "[email protected]";
dbc.Users.AddObject(newUser); // ERROR !
dbc.SaveChanges();
return flag;
}
However, on the "add object line" it gives me the follow error --->
Error "The best overloaded method match for System.Data.Objects.ObjectSet<Guild_Chat.User>.AddObject(Guild_Chat.User)' has some invalid arguments ".
Upvotes: 0
Views: 127
Reputation: 103365
Try adding the actual entity type Guild_Chat.User
, for example:
public bool InsertDefaultUser()
{
try
{
Guild_Chat.User newUser = new Guild_Chat.User
{
alias = "bulby",
password = "chicken",
email = "[email protected]"
};
dbc.Users.AddObject(newUser);
dbc.SaveChanges();
return true;
}
catch(Exception e)
{
return false;
}
}
Upvotes: 1