2012-02-09 2 views
1

私はmystoreシャープライトアーキテクチャの例を使用します。ここでソリューションをダウンロードすることができます: https://github.com/codai/Sharp-LiteSharp Liteアーキテクチャを使用したASP.NET MVC 3で結合クエリを実行

したがって、問題のエンティティは2つあります。製品。そしてProductCategories。それはそれで製品のリストのリストを持っている

public class Product : Entity 
{ 
    public Product() { 
     Categories = new List<ProductCategory>(); 
    } 

    [DomainSignature] 
    [Required(ErrorMessage = "Name must be provided")] 
    [StringLength(255, ErrorMessage = "Name must be 255 characters or fewer")] 
    public virtual string Name { get; set; } 

    /// <summary> 
    /// Money is a component, not a separate entity; i.e., the Products table will have column 
    /// for the amount 
    /// </summary> 
    [DataType("Money")] 
    public virtual Money Price { get; set; } 

    /// <summary> 
    /// many-to-many between Product and ProductCategory 
    /// </summary> 
    [Display(Name="Product Categories")] 
    public virtual IList<ProductCategory> Categories { get; protected set; } 
} 

お知らせ:

製品は、次のようになります。したがって、それに適用されるProductCategoriesのリストがあります。

そして、ここでは、ProductCategoryです:

public class ProductCategory : Entity 
{ 
    public ProductCategory() { 
     Children = new List<ProductCategory>(); 
     Products = new List<Product>(); 
    } 

    [DomainSignature] 
    [Required(ErrorMessage="Name must be provided")] 
    [StringLength(255, ErrorMessage="Name must be 255 characters or fewer")] 
    public virtual string Name { get; set; } 

    /// <summary> 
    /// many-to-one from child ProductCategory to parent ProductCategory 
    /// </summary> 
    [Display(Name="Parent Category")] 
    public virtual ProductCategory Parent { get; set; } 

    /// <summary> 
    /// many-to-many between ProductCategory and Product 
    /// </summary> 
    public virtual IList<Product> Products { get; protected set; } 

    /// <summary> 
    /// one-to-many from parent ProductCategory to children ProductCategory 
    /// </summary> 
    public virtual IList<ProductCategory> Children { get; protected set; } 
} 

は、私は私がどこ文で簡単なものを作っていることを十分にクエリを理解しています。たとえば、これは別のプログラムで顧客の名字を検索するために使用したクエリです。

public static IQueryable<Customer> GetByFirstName(this IQueryable<Customer> customers, string name) 
    { 
     name = name.ToUpper(); 
     return 
      customers.Where(c => c.BillingAddress.FirstName.ToUpper().Contains(name)); 
    } 

しかし、私はまだジョインを理解していません。誰かが私に光を見せてくれますか?

+1

Sharp Liteとの関係について教えてください。あなたは何をしようとしていますか、なぜあなたは結合が必要だと思いますか? –

+1

あなたは何を達成しようとしていますか? –

+0

申し訳ありませんが、私は明確ではありませんでした。私はProductCategoryによる製品の問い合わせをしようとしています。 – Bill

答えて

1

まず、参加の仕方がわからない場合は、ドキュメントの一部を参照してください。ただし、Sharp Liteとはほとんど関係ありません。

シャープライトの背後にある基本的なアイデアは、基本的なデータアクセス(NHやEFが一番人気がある)にあまり依存しないために、IQueryableの能力を利用することだから、基本的にhow joins work on NH NH)を使用して作業を開始します。また、より複雑な構造を持つより良い例を作成して、実際に結合を行うこともできます。

SharpLiteでジャンプスタートが必要な場合は、the post on why Sharp lite existsthe other explaining how it's builtを必ず読んでください。また、デモプロジェクトでone myself to get people startedを作った。

希望すると助かります!

+0

はい、これは私が最終的に考え出したものです。私は助けが必要なNHの問題です。シャープライトではありません。申し訳ありません、これは私の最初のWebアプリケーションです。そして、何が何であるかを理解することは少し難しいです。 – Bill

+0

心配する必要はありません。お手伝いできます... https://groups.google.com/group/sharp-lite/のSharp Liteのディスカッションリストを必ず確認してください。 –