none
How to iterate tables in DBContext? RRS feed

  • Question

  • Hi, i am trying to serialize all the tables in DBContext, can anybody advise me how to achieve this?  For say:

    i have my DBContext class here,

    public partial class MyTestDBModel : DbContext 
    { 
    public MyTestDBModel() 
    : base("name=MyTestDBModel") 
    { 
    } 
    
    protected override void OnModelCreating(DbModelBuilder modelBuilder) 
    { 
    throw new UnintentionalCodeFirstException(); 
    } 
    
    public DbSet<Table1> Table1 { get; set; } 
    public DbSet<Table2> Table2 { get; set; } 
    } 
    
    i want to serialize the records in Table1/Table2, but i have to do this programly, so the method would be something like this:
    public static void Serialize( DbContext source, string xmlFileLocation) 
    { 
    }
    
    how can i achieve this?


    thanks, eric

    Wednesday, December 7, 2011 8:02 AM

Answers