none
How to pass a class type to CTOR RRS feed

  • Question

  •     public class Repository<T> where T:class
        {
            private ObjectContext context;
            private string connectionString;
          
            public Repository (string ConnectionString) 
            {
                
                connectionString = ConnectionString;
                context = new ObjectContext(ConnectionString);
            }
    
            public IEnumerable<T> Get<T>(Expression<Func<T, bool>> predicate) where T : class
            {
                
                var stuff = context.CreateObjectSet<T>().Where(predicate);
                return stuff.ToList<T>();
            }
    Given the code above I want the T to be known on the GET method from the CTOR of the Class... That way I don't have to explicitly define it everytime I use the GET method.   Any hints are appreaciated.

    JP Cowboy Coders Unite!


    Monday, November 12, 2012 7:22 PM

Answers

  • I think this does the job, I removed the <T> from the Get

            public IEnumerable<T> Get(Expression<Func<T, bool>> predicate) 
            {
                
                var stuff = context.CreateObjectSet<T>().Where(predicate);
                return stuff.ToList<T>();
            }


    JP Cowboy Coders Unite!

    Monday, November 12, 2012 7:30 PM

All replies

  • I think this does the job, I removed the <T> from the Get

            public IEnumerable<T> Get(Expression<Func<T, bool>> predicate) 
            {
                
                var stuff = context.CreateObjectSet<T>().Where(predicate);
                return stuff.ToList<T>();
            }


    JP Cowboy Coders Unite!

    Monday, November 12, 2012 7:30 PM
  • Hi Javaman,

    Welcome to the MSDN forum.

    Thank you for you sharing. Have a nice day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, November 14, 2012 2:05 AM