This project is read-only.

Get Entity with Depending items

1. Select Entity With Depending items

Initialization:

public void Init(IUnityContainer container)
{
    container.RegisterSimpleSql<Development>(
        d=>d.FirstMultiReaderSetIsForEntity()
        .AddMultiProperties<FindOneWithRelatedPlotsCommandParameter>(
        p=> new
                {
                    NewsItems = p.MultiMap<Plot,Development>(t=>t.Plots, (a,b) => true)
                }
        ));
}

Stored Procedure

CREATE PROCEDURE [dbo].[cusp_DevelopmentFindOneWithRelatedPlots]
	@Id int
AS
BEGIN
	SELECT d.*  FROM Developments d	
	where d.Id = @Id
	
	SELECT p.* FROM Plots p
	where p.DevelopmentId = @Id
END

2. Select Entity With Depending items (2 levels of dependency)

Domain entities:

using Fuse8.DomainFramework.Domain;

public class Development : Int32EntityObject
{
    public List<HouseType> HouseTypes { get; set; }
}

public class HouseType : Int32EntityObject
{
    public List<Plot> Plots { get; set; }
}

Initialization:

public void Init(IUnityContainer container)
{
    container.RegisterSimpleSql<Development>(
        d=>d.FirstMultiReaderSetIsForEntity()
        .AddMultiProperties<FindOneWithRelatedPlotsCommandParameter>(
        p=> new
                {
                    HouseTypes = p.MultiMap<HouseType,Development>(h=>h.HouseTypes, (a,b) => true),
                    Plots = p.MultiMap<Plot,HouseType>(t => t.Plots, x => x.HouseType, (x, t) => x.HouseTypeId == t.Id)
                }
        ));
}

Stored Procedure

CREATE PROCEDURE [dbo].[cusp_DevelopmentFindOneWithRelated]
	@Id int
AS
BEGIN
	SELECT d.*  FROM Developments d	
	where d.Id = @Id
	
	SELECT 	ht.* from HouseTypes ht	
	where ht.Id in (select p.HouseTypeId from Plots p where p.DevelopmentId = @Id)
	
	SELECT p.*, ht.Id as HouseTypeId FROM Plots p
	inner join HouseTypes ht on p.HouseTypeId = ht.Id
	where p.DevelopmentId = @Id 
END

Last edited Apr 1, 2013 at 6:12 AM by olgabutova, version 3

Comments

No comments yet.