1

I’m trying to create class from abstract one:

public class ManufacturerEntityService : BaseEntityService<Manufacturer>
{
    Entities entities = new Entities();

    protected override ObjectSet<Manufacturer> EntitySet
    {
        get { return entities.Manufacturers; }
    }

}

Error occurred:

Cannot implicitly convert type 'System.Data.Entity.DbSet<_21century.Models.Manufacturer>' to 'System.Data.Objects.ObjectSet<_21century.Models.Manufacturer>'

In BaseEntityService i’ve used ObjectSet, cause DbSet doesn’t have SaveData method. The question is how to convert ObjectSet to DbSet? Is it possible or not? Any walkarounds? I have to pass DbContext obj there?

I’m newbie in creating mvc projects. Searching didn’t give any result. Hope someone can help me.

Sam Axe
  • 33,313
  • 9
  • 55
  • 89
Mykhailo
  • 121
  • 1
  • 6
  • Why are you using SaveData in your DbSet? That should be done on the DbContext. – Scottie Mar 25 '15 at 21:24
  • `ObjectSet.SaveData` doesn't exist. Is this some homebrewn extension method? But anyway, I'd always try to turn away from the legacy `ObjectSet` and replace it for the more developer-friendly `DbSet`. I don't know how much impact this would have on your code, but I'm sure it's worth the effort. – Gert Arnold Mar 25 '15 at 21:39

1 Answers1

0

The answer can be found here: How to convert DbSet in Entity framework to ObjectQuery

public class ManufacturerEntityService : BaseEntityService<Manufacturer>
{
    Entities entities = new Entities();

    protected override ObjectSet<Manufacturer> EntitySet
    {
        get 
        { 
            ObjectContext objectContext = entities.ObjectContext;  
            return objectContext.CreateObjectSet<Manufacturer>("Manufacturers");
        }
    }

}
Community
  • 1
  • 1
Keith Payne
  • 3,002
  • 16
  • 30
  • 1
    Better to mark as duplicate than to copy an answer, esp. when you don't copy it correctly (`entities.ObjectContext`). But while this answers the OP's direct question, it's probably not the best way to go. – Gert Arnold Mar 25 '15 at 21:34