user3474542
user3474542

Reputation: 33

Error .The entity type List`1 is not part of the model for the current context

Hi I am getting the error The entity type List`1 is not part of the model for the current context at the following line of code

 if (bureauEntities.Entry(subscription).State == EntityState.Detached)

 public ActionResult UnSubscribe(int subscriptionTypeId, int companyId)
    {
        if (ModelState.IsValid)
        {
              using (BUREAUEntities bureauEntities = new BUREAUEntities())
                {
                    var subscription = new SubcriptionRepository()
                   .AllIncluding(x => x.Exchanges, x => x.Users)
                   .ToList<Avanade.Bureau.DataAccessLayer.DatabaseModel.Subscription>().ToList<Avanade.Bureau.DataAccessLayer.DatabaseModel.Subscription>()
                   .Where(x => x.SubscriptionTypeId == subscriptionTypeId && x.CompanyId == companyId)// put where clasue here
                   .ToList<Avanade.Bureau.DataAccessLayer.DatabaseModel.Subscription>();


                    if (bureauEntities.Entry(subscription).State == EntityState.Detached)
                    {
                        // bureauEntities.Subscriptions.Attach(subscription);
                    }
                    //bureauEntities.Subscriptions.Remove(subscription);
                    bureauEntities.SaveChanges();

                }
}

Could some one tell me what is the problem with the code?

Upvotes: 0

Views: 3435

Answers (1)

user3559349
user3559349

Reputation:

DbContext.Entry(object) expects a single object. You are passing it a List<>. If you are expecting the the LINQ method to return only one value, append `.FirstOrDefault() to the query

Upvotes: 1

Related Questions