views:

113

answers:

3

How can you make something like this generic

return from items in _db.Table
    select items;

I would like to do something like this

public class Data<T> ( where T is the model object )

so the Table will change to the value of T

How would this look as a generic class with a save method for instance

Thanks

A: 
... _db.GetTable<MyType> ...
leppie
+4  A: 

In LINQ-to-SQL, the data-context has GetTable<T>():

var table = _db.GetTable<T>();
etc
Marc Gravell
var table = _db.GetTable<T>;Error 1 Cannot assign method group to an implicitly-typed local variable
Did you mean this for leppie? I had brackets in my post... try adding them...
Marc Gravell
+1  A: 

Adding to Marc Gravell's answer, you could have a generic update method that looks like this:

public void Update(TEntity entity, TEntity original)
{
    using (DataContext context = CreateContext())
    {
        Table<TEntity> table = context.GetTable<TEntity>();

        table.Attach(entity, original);
        context.SubmitChanges();
    }
}
jrummell