2012-02-09 2 views
1

mystore sharp lite 아키텍처 예제를 사용합니다. 여기에서 솔루션을 다운로드 할 수 있습니다. https://github.com/codai/Sharp-LiteSharp Lite 아키텍처를 사용하는 ASP.NET MVC 3에서 결합 쿼리 수행

따라서 두 개의 엔티티가 있습니다. 제작품. 그리고 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에 적용되는 목록이 있습니다.

그리고 여기가 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

먼저 Join을 만드는 방법을 이해하지 못한다면 Sharp Lite와는 거의 관계가없는 일부 문서를 참조해야합니다.

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 문제입니다. 샤프 라이트가 아닙니다. 죄송합니다. 내 첫 번째 웹 앱입니다. 그리고 무엇이 무엇인지 알아내는 것은 약간 어렵습니다. – Bill

+0

걱정할 필요가 없습니다. 도움이 될만한 정보 ... https://groups.google.com/group/sharp-lite/에서 Sharp Lite 토론 목록을 확인하십시오. –

관련 문제