objectset

MusicStore 'System.Data.Objects.ObjectSet<…>' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument

我是研究僧i 提交于 2020-01-04 02:29:16
问题 I'm following the MusicStore tutorial I'm already on the Part 8 of the tutorial. I got this error when I tried to add the ShoppingCart class.. I tried to google for a possible solution but failed to find a clean one T_T .. based on my research I'm getting this error because I'm using edmx which is database first instead of code first on the tutorial. I had this codes added and is having an error on Add() and Remove() namespace Project.Models { public partial class ShoppingCart {

Generic ObjectContext? objectContext.GetObjectSet<TEntity>?

只愿长相守 提交于 2019-12-25 00:43:23
问题 Is there a way to get ObjectQuery<T> for specfied generic type? Pseudo: public partial class MyObjectContext { public ObjectSet<TEntity> GetObjectSet<TEntity>() { return Helper.GetObjectSet<TEntity>(this); } } 回答1: Yes this is what you need: public partial class MyObjectContext { public ObjectSet<TEntity> GetObjectSet<TEntity>() { return this.CreateObjectSet<TEntity>(); } } As you can see your helper method is not needed because you can call CreateObjectSet directly on MyObjectContext

Entity Framework: ObjectSet and its (generics) variance

安稳与你 提交于 2019-12-01 21:25:08
问题 I use: EntityFramework + POCO Here is the thing: public interface IBaseType { int Id { get; set; } } public class BaseType : IBaseType { public virtual int Id { get; set; } } public class DerivedType : BaseType { } The problem: public class EntityFetcher<T> where T : BaseType { public object GetById(int id) { ObjectSet<T> objectSet = (ObjectSet<T>)GetTheObjectSet(typeof(T)); return objectSet.SingleOrDefault((o) => o.Id == id); } } If T is BaseType this all works perfectly, but: The problem is