1
public class SomeRepository<TContext> : IDisposable
            where TContext : DbContext, new()
        {
            protected TContext context;
            protected SomeRepository()
            { }

        public virtual void Create<T>(T item) where T : class, new()
        {
            ...
        }
    }

    internal class SomeCrud : SomeRepository<SomeContext>
    {
        public override void Create(Product item)
        {
            ....
        }     
    }

}

public override void Create(Product item) not appropriate method found to override でエラーが発生しました。誰かが間違いを見てください。私がこのように書いている場合:

        public override void Create<Product>(Product item)
        {
            ....
        }

製品タイプが表示されません ありがとう

4

1 に答える 1

2

このソリューションを探していると思います:

public class SomeRepository<TContext, T> where TContext : DbContext where T : class, new()
{
    public virtual void Create(T item) { }
}

internal class SomeCrud : SomeRepository<SomeContext, Product>
{
    public override void Create(Product item) { }
}

実際には、一般的な定義で製品の制約を定義する必要があります。に注意してTくださいSomeRepository<TContext, T>


あなたが試すことができます

    public void Create<T>(T item) where T : Product
    {           
    }

しかし、なぜジェネリックを使用するのでしょうか?

于 2012-06-19T11:25:35.100 に答える