2016-10-05 4 views
-2

私のアプリケーションには多言語データベースがあります。ユーザープログラムで設定された言語のデータベースからリストをロードする必要があります。私はDblingライブラリを使用し、3日間で頭部を傷つけ、動的にデータベースからデータを取り込み、linq要求を構築します。次の表に、次の列を示します。C#linqと多言語データベース

id |名前| name_ru

デフォルト言語はロシア語であるとします。

public class ListRegistered 
    { 
     private int _id; 
     private string _name; 

     public ListRegistered() 
     { 

     } 

     public int ID 
     { 
      get { return this._id; } 
      set { this._id = value; } 
     } 

     public string Name 
     { 
      get { return this._name; } 
      set { this._name = value; } 
     } 
    } 

は、今、私がリクエストします:アプリケーションを初期化するときに、私は、データを格納するPOCOクラスを作成し、

DbMetal utility created my class: 

    // 
    // ____ _  __ __  _  _ 
    // | _ \| |__ | \/ | ___| |_ __ _| | 
    // | | | | '_ \| |\/| |/ _ \ __/ _` | | 
    // | |_| | |_) | | | | __/ || (_| | | 
    // |____/|_.__/|_| |_|\___|\__\__,_|_| 
    // 
    // Auto-generated from main on 2016-09-30 22:24:51Z. 
    // Please visit http://code.google.com/p/dblinq2007/ for more information. 
    // 
    using System; 
    using System.ComponentModel; 
    using System.Data; 
    #if MONO_STRICT 
     using System.Data.Linq; 
    #else // MONO_STRICT 
     using DbLinq.Data.Linq; 
     using DbLinq.Vendor; 
    #endif // MONO_STRICT 
     using System.Data.Linq.Mapping; 
    using System.Diagnostics; 

    namespace MMS.Model.Test 
    { 
     public partial class Main : DataContext 
     { 

      #region Extensibility Method Declarations 
      partial void OnCreated(); 
      #endregion 

      partial void OnCreated() 
      { 

      } 
      public Main(string connectionString) : 
       base(connectionString) 
      { 
       this.OnCreated(); 
      } 

      public Main(string connection, MappingSource mappingSource) : 
       base(connection, mappingSource) 
      { 
       this.OnCreated(); 
      } 

      public Main(IDbConnection connection, MappingSource mappingSource) : 
       base(connection, mappingSource) 
      { 
       this.OnCreated(); 
      } 
    public Table<ListLips> ListLips 
      { 
       get 
       { 
        return this.GetTable<ListLips>(); 
       } 
      } 
[Table(Name = "main.list_lips")] 
    public partial class ListLips : System.ComponentModel.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged 
    { 

     private static System.ComponentModel.PropertyChangingEventArgs emptyChangingEventArgs = new System.ComponentModel.PropertyChangingEventArgs(""); 

     private int _id; 

     private string _nameRu; 

     private string _nameEn; 

     #region Extensibility Method Declarations 
     partial void OnCreated(); 

     partial void OnIDChanged(); 

     partial void OnIDChanging(int value); 

     partial void OnNameRuChanged(); 

     partial void OnNameRuChanging(string value); 

     partial void OnNameENChanged(); 

     partial void OnNameENChanging(string value); 
     #endregion 


     public ListLips() 
     { 
      this.OnCreated(); 
     } 

     [Column(Storage = "_id", Name = "id", DbType = "INTEGER", IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.Never, CanBeNull = false)] 
     [DebuggerNonUserCode()] 
     public int ID 
     { 
      get 
      { 
       return this._id; 
      } 
      set 
      { 
       if ((_id != value)) 
       { 
        this.OnIDChanging(value); 
        this.SendPropertyChanging(); 
        this._id = value; 
        this.SendPropertyChanged("ID"); 
        this.OnIDChanged(); 
       } 
      } 
     } 

     [Column(Storage = "_nameRu", Name = "name_ru", DbType = "VARCHAR (30)", AutoSync = AutoSync.Never)] 
     [DebuggerNonUserCode()] 
     public string NameRu 
     { 
      get 
      { 
       return this._nameRu; 
      } 
      set 
      { 
       if (((_nameRu == value) 
          == false)) 
       { 
        this.OnNameRuChanging(value); 
        this.SendPropertyChanging(); 
        this._nameRu = value; 
        this.SendPropertyChanged("NameRu"); 
        this.OnNameRuChanged(); 
       } 
      } 
     } 

     [Column(Storage = "_nameEn", Name = "name_en", DbType = "VARCHAR (30)", AutoSync = AutoSync.Never)] 
     [DebuggerNonUserCode()] 
     public string NameEN 
     { 
      get 
      { 
       return this._nameEn; 
      } 
      set 
      { 
       if (((_nameEn == value) 
          == false)) 
       { 
        this.OnNameENChanging(value); 
        this.SendPropertyChanging(); 
        this._nameEn = value; 
        this.SendPropertyChanged("NameEN"); 
        this.OnNameENChanged(); 
       } 
      } 
     } 

     public event System.ComponentModel.PropertyChangingEventHandler PropertyChanging; 

     public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; 

     protected virtual void SendPropertyChanging() 
     { 
      System.ComponentModel.PropertyChangingEventHandler h = this.PropertyChanging; 
      if ((h != null)) 
      { 
       h(this, emptyChangingEventArgs); 
      } 
     } 

     protected virtual void SendPropertyChanged(string propertyName) 
     { 
      System.ComponentModel.PropertyChangedEventHandler h = this.PropertyChanged; 
      if ((h != null)) 
      { 
       h(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName)); 
      } 
     } 
    } 
     } 
} 

また、ロシア語ですべての情報を取る必要があり

public class PersonInformationModel 
    { 

     private static string language = "ru" // We assume that this is the current language; 


     public List<MMS.Model.POCO.ListRegistered> GetRegisteredList() 
     { 
      Main dbContext = new Main(DatabaseConnect.GetConnectionContext(), new SqliteVendor()); 

var q = (from o in dbContext.ListRegistered select new MMS.Model.POCO.ListRegistered() { 
    Name = // <------- How do I get here to dynamically o.NameRu or o.NameEn??? 
}); 
} 
} 
+2

これは非常に知っていることですが、あなたは実際の質問をしたいかもしれません。 – sokkyoku

答えて

0

言語ごとに1列ではなく、変換用のテーブルがある場合は、LINQで簡単に実行できます(これは非常にスケーラブルで、後であなたを傷つけることになります)。

あなたの状況では、あなたのPocoの名前にプロパティを追加するだけです。そのロジックを行うゲッターを使用します(つまり、必要な言語に基づいてスイッチの正しい列を返します)。魔法のように「列」を選択する方法はありません