2012-01-30 11 views
0

データレイヤにEF 4.1 - コードファーストを使用するWebFormsアプリケーションがあります。私は多対多の関係を持っています。レポジトリパターンをコードファーストで使用して、GridView内で多対多の関係を表示

public class Application 
{ 
    public Application() 
    { 
     Administrators = new List<User>(); 
    } 

    public long Id { get; set; } 

    public string Name { get; set; } 

    public virtual ICollection<User> Administrators { get; set; } 
} 

public class User 
{ 
    public User() 
    { 
     Administrates = new List<Application>(); 
    } 

    public long Id { get; set; } 

    public string FirstName { get; set; } 

    public string LastName { get; set; } 

    public string Username { get; set; } 

    // Collections 
    public virtual ICollection<Application> Administrates { get; set; } 
} 

の構成を仮定すると、管理者は、管理者ごとに1つのレコードの列で、各アプリケーションエンティティのために誰であるかを示すためにGridViewのにバインドされたのObjectDataSourceを実装する方法があり、正しくセットアップされています。今、私はこの問題に取り組むためにViewとStoredProcsでSqlDataSourceを使用していますが、私は自分のデータレイヤーのための1つのアーキテクチャパターンに固執したいと思います。

答えて

1

このチュートリアルでは、最初のデータベース最初のではなく、コードを使用していますが、それ以外、あなたが探しているものに似ていますし、何か役に立つかもしれないという例があります:私はこれは私が探しています何だと思います

http://www.asp.net/web-forms/tutorials/continuing-with-ef/using-the-entity-framework-and-the-objectdatasource-control-part-3-sorting-and-filtering

+0

をために。 GridViewからのデータをDelete、Insert、Updateメソッドにどのようにバインドするのですか? 'void Update(Guid applicationId、Guid userId)'を呼び出し、これらのパラメータを使用してコンテキストオブジェクトから正しいオブジェクトを取得しますか? – bdparrish

関連する問題