Я не знаю почему, но во всех уроках, которые я видел, есть DBObject.TableObject.Add(newObject);
.Я не уверен, почему, но в моем случае нет.
Код
[HttpPost]
public ActionResult Index(Post newPost)
{
if (TryUpdateModel(newPost) == true)
{
string[] tagList = { "tag1", "tag2", "tag3"};
_db.Posts.InsertOnSubmit(newPost);
_db.SubmitChanges();
foreach (string tag in tagList)
{
var newTag = new Tag();
if (_db.Tags.Any(x => x.TagName == tag))
{
newTag = (from t in _db.Tags
where t.TagName == tag
select t).Single();
}
else
{
newTag = new Tag()
{
TagName = tag
};
}
// Does not work
_db.Tags.Add(newTag);
var postTag = new PostTag()
{
Tag = newTag,
Post = newPost
};
// Does not work
_db.PostTags.Add(postTag);
}
return Content(Convert.ToString(newPost.ID));
return RedirectToAction("List");
}
else
{
return Content("Fail.");
}
}
Ошибка
Error 1 'System.Data.Linq.Table<MvcApplication1.Models.Tag>' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'System.Data.Linq.Table<MvcApplication1.Models.Tag>' could be found (are you missing a using directive or an assembly reference?) C:\Users\Qmal\documents\visual studio 2010\Projects\MvcApplication1\MvcApplication1\Controllers\HomeController.cs 47 30 MvcApplication1
Ссылка?У меня есть все ссылки LINQ, это странно для меня.
PS Я не уверен, правильно ли все делаю, но все же это странно.