두 개의 다른 생성 된 linq 코드를 사용할 때 Rob Conery가 [MVC Storefront] [1]에서 보여주는 소위 "리포지토리 패턴"을 어떻게 구현할 수 있습니까? Fredrik Normen이 What purpose does the Repository Pattern have?에 토론 할 때 실제 저장소 패턴을 구현해야합니까? 문제는 LINQ가 내 "저장소"에서 제공하는 멋진 기능 중 일부를 전달하여 나중에 사용할 수 있기 때문에 필요하지 않은 경우 Fredrik에서 논의한 실제 저장소 패턴을 구현하고 싶지 않다는 것입니다.리포지터리 패턴 linq 사용
내 문제가 있습니다. 나는 [dblinq] [3]을 다운로드 받았는데, 이것은 MySQL, Oracle, PostgreSQL을위한 Linq Provider이다. 내 프로젝트에서 나는 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