How to pass actual Table entity rather than System.Data.Linq.Table<TEntity> RRS feed

  • Question

  • Guys


    I have an extension which employs the following syntax:


    public static void Insert<TEntity>(this DataContext db, Func<TEntity, int> tableKeySelector, string title) where TEntity : class{...


    which eventually calls:


    var inserts = db.GetChangeSet().Inserts.OfType<TEntity>();


    I would like to make this more 'dynamic' by, say, checking which tables have a column called 'version' and operating on those only.  Maybe in my DataContext extension...


    foreach (MetaTable metatable in this.Mapping.GetTables())


    // get the columns stuff...

    ReadOnlyCollection<MetaDataMember> fields = metatable.RowType.DataMembers;

    foreach (MetaDataMember item in fields)


    if ("version" == item.Name)


    var table = this.GetTable(metatable.RowType.Type);


    // this works...

    this.Insert<aaTestTable>(dt =>, metatable.TableName.ToString());

    // but we want something like....

    //this.Audit<metatable.TableName.ToString()>(dt =>, metatable.TableName.ToString());





    Hope this is clear.  Any ideas on how I can approach this...





    Friday, August 15, 2008 7:51 AM


  • I'm not finding this entirely clear... Are you wanting to do something like:


    this.Audit<metatable.RowType.Type>(dt =>, metatable.TableName.ToString());



    Monday, August 18, 2008 7:48 PM