RobCon Coneryが[MVC Storefront] [1]で示した、いわゆる2つの異なるlinqコードを使用すると、いわゆる「リポジトリパターン」をどのように実装できますか? Fredrik Normenが議論しているように、実際のリポジトリパターンを実装する必要がありますか?What purpose does the Repository Pattern have??それは、LINQが私の "リポジトリ"から提供する素敵な機能の一部を私が後で使うことができるようにするためです。そうでない場合は、Fredrikが議論したように実際のリポジトリパターンを実装したくありません。linqを使用したリポジトリパターン
問題が発生しました。私はMySql、Oracle、PostgreSQLのLinqプロバイダである[dblinq] [3]をダウンロードしました。私のプロジェクトでは、MySQLとSQL(マイクロソフト)用のLINQコードを生成しました。問題は、同じ名前のクラスを生成する必要があることですが、コンテンツは多少異なります。どういうわけか、これをネームスペースや何かで実装して、どちらも使えるようにすることができますか?「リポジトリパターン」のアイデアですか? 例SQL
言語テーブルの[Table(Name="dbo.Language")]
public partial class Language : INotifyPropertyChanging, INotifyPropertyChanged
{
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
private int _Id;
private string _Name;
private EntitySet<Book> _Books;
#region Extensibility Method Definitions
partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
partial void OnIdChanging(int value);
partial void OnIdChanged();
partial void OnNameChanging(string value);
partial void OnNameChanged();
#endregion
public Language()
{
this._Books = new EntitySet<Book>(new Action<Book>(this.attach_Books), new Action<Book>(this.detach_Books));
OnCreated();
}
[Column(Storage="_Id", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
public int Id
{
get
{
return this._Id;
}
set
{
if ((this._Id != value))
{
this.OnIdChanging(value);
this.SendPropertyChanging();
this._Id = value;
this.SendPropertyChanged("Id");
this.OnIdChanged();
}
}
}
[Column(Storage="_Name", DbType="NVarChar(100) NOT NULL", CanBeNull=false)]
public string Name
{
get
{
return this._Name;
}
set
{
if ((this._Name != value))
{
this.OnNameChanging(value);
this.SendPropertyChanging();
this._Name = value;
this.SendPropertyChanged("Name");
this.OnNameChanged();
}
}
}
[Association(Name="Language_Book", Storage="_Books", ThisKey="Id", OtherKey="Language")]
public EntitySet<Book> Books
{
get
{
return this._Books;
}
set
{
this._Books.Assign(value);
}
}
public event PropertyChangingEventHandler PropertyChanging;
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void SendPropertyChanging()
{
if ((this.PropertyChanging != null))
{
this.PropertyChanging(this, emptyChangingEventArgs);
}
}
protected virtual void SendPropertyChanged(String propertyName)
{
if ((this.PropertyChanged != null))
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private void attach_Books(Book entity)
{
this.SendPropertyChanging();
entity.Language1 = this;
}
private void detach_Books(Book entity)
{
this.SendPropertyChanging();
entity.Language1 = null;
}
}
MySQLの
[Table(Name = "asp.Language")]
public partial class Language : INotifyPropertyChanged
{
#region INotifyPropertyChanged handling
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
#region int ID
private int _id;
[DebuggerNonUserCode]
[Column(Storage = "_id", Name = "Id", DbType = "int", IsPrimaryKey = true, IsDbGenerated = true, CanBeNull = false)]
public int ID
{
get
{
return _id;
}
set
{
if (value != _id)
{
_id = value;
OnPropertyChanged("ID");
}
}
}
#endregion
#region string Name
private string _name;
[DebuggerNonUserCode]
[Column(Storage = "_name", Name = "Name", DbType = "varchar(100)", CanBeNull = false)]
public string Name
{
get
{
return _name;
}
set
{
if (value != _name)
{
_name = value;
OnPropertyChanged("Name");
}
}
}
#endregion
#region Children
private EntitySet<Book> _book;
[Association(Storage = "_book", OtherKey = "Language", ThisKey = "ID", Name = "Book_ibfk_1")]
[DebuggerNonUserCode]
public EntitySet<Book> Book
{
get
{
return _book;
}
set
{
_book = value;
}
}
#endregion
#region Attachement handlers
private void Book_Attach(Book entity)
{
entity.LanguageLanguage = this;
}
private void Book_Detach(Book entity)
{
entity.LanguageLanguage = null;
}
#endregion
#region ctor
public Language()
{
_book = new EntitySet<Book>(Book_Attach, Book_Detach);
}
#endregion
}
ありがとうございました。 SubSonicは確かに有望に見えます。しかし、私はそのようなものを使用し始める前に.netについてもっと学びたいと思っています(私はちょうど.netを今一週間試しました)。 – unkownt