fiogf49gjkf0d I found your post. I am currently getting the same error from a piece of sample code on a Entity/MVC4 tutorial. I have found these two pages so far that might help you.
http://msdn.microsoft.com/en-us/library/system.data.entitystate.aspx
http://social.msdn.microsoft.com/Forums/pl/adodotnetentityframework/thread/f36865b1-aecf-4db8-8106-402f4da3dd33
Here is the code that is giving me a similar problem:
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.ComponentModel.DataAnnotations;
using
System.Data.Entity;
using
TutorialFromOnline.Models.Abstract;
using
TutorialFromOnline.Models;
using
System.Data.Objects.DataClasses;
namespace
TutorialFromOnline.Models
{
public class ReviewRepository : IReviewRepository
{
private ReviewedContext _db { get; set
; }
public ReviewRepository() : this(new ReviewedContext
())
{ }
public ReviewRepository(ReviewedContext
db) { _db = db; }
public Review Get(int
id)
{
return
_db.Reviews.SingleOrDefault(r => r.Id == id);
}
public IQueryable<Review
> GetAll()
{
return
_db.Reviews;
}
public Review Add(Review
review)
{
_db.Reviews.Add(review); _db.SaveChanges();
return
review;
}
public Review Update(Review
review)
{
_db.Entry(review).State = EntityState.Modified;
_db.SaveChanges();
return
review;
}
public void Delete(int
reviewId)
{
var
review = Get(reviewId);
_db.Reviews.Remove(review);
}
public IEnumerable<Review> GetByCategory(Category
category)
{
return
_db.Reviews.Where(r => r.CategoryId == category.Id);
}
public IEnumerable<Comment> GetReviewComments(int
id)
{
return
_db.Comments.Where(c => c.ReviewId == id);
}
}
I got this code from the following tutorial.
http://net.tutsplus.com/tutorials/building-an-asp-net-mvc4-application-with-ef-and-webapi/
I hope this helps. I'm not getting anywhere with this issue.
|