2012-05-11 4 views
0

私はテーブルをマップするためのコードを書いていますempId empName salaryフィールドを含むemp。 しかし、それはforループに達すると、button1クリックで例外の無効なアプリケーションセッションIDをスローします。それを修正するための助けが必要です。私はEmpname = ssのempIdを表示したい。Wp7データ接続性の例外

private const string ConnectionString = "isostore:/Emp1.sdf";

[Table(Name = "Emp")] 
    public class Emp2 
    { 
     [Column(IsPrimaryKey = true, IsDbGenerated = true)] 
     public int EmpId 
     { 
      get; 
      set; 
     } 
     [Column] 
     public string EmpName 
     { 
      get; 
      set; 
     } 
     [Column] 
     public int Salary 
     { 
      get; 
      set; 
     } 
    } 


    public MainPage() 
    { 
     InitializeComponent(); 

     using (CountryDataContext context = new CountryDataContext(ConnectionString)) 
     { 

      if (!context.DatabaseExists()) 
      { 

       context.CreateDatabase(); 

      } 
      else 
      { 
       MessageBox.Show("Employee table exist already"); 
      } 
     } 




    } 


    private IList<Emp2> getcountry() 
    { 
     IList<Emp2> countryList = null; 
     using (CountryDataContext context = new CountryDataContext(ConnectionString)) 
     { 
      IQueryable<Emp2> query = from c in context.Emp where c.EmpName=="ss" select c; 
      countryList = query.ToList(); 
     } 

     return countryList; 
    } 



    public class CountryDataContext : DataContext 
    { 
     public CountryDataContext(string connectionString) 
      : base(connectionString) 
     { 

     } 
     public Table<Emp2> Emp 
     { 
      get 
      { 
       return this.GetTable<Emp2>(); 
      } 
     } 


    } 

    private void button1_Click(object sender, RoutedEventArgs e) 
    { 
     IList<Emp2> emp= this.getcountry(); 

     try 
     { 
      foreach (Emp2 a in emp) 
      { 
       MessageBox.Show(a.EmpId.ToString()); 

      } 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show(ex.Message); 
     } 


    } 

答えて

0

wp7explorerを使用している可能性はありますか? 私も同様の問題があり、wp7explorerを無効にすると問題が解決しました。 http://wp7explorer.codeplex.com/workitem/8259

詳細については、このリンクをチェックアウト

関連する問題