Mapping fields in BLToolkit for class properties

My table layout (excerpt)

create table dbo.MyEntity
(
    MyEntityID int identity not null
        primary key,
    Name nvarchar(50) not null
        unique,
    Description nvarchar(500) null,
    -- these two are optional fields
    MaxCount int null,
    MinSpace int null
)

Entity Class (es)

[MapField("MaxCount", "Rule.MaxCount")]
[MapField("MinSpace", "Rule.MinSpace")]
public class MyEntity
{
    public int Id { get; set; }

    public string Name { get; set; }

    public string Description { get; set; }

    // when values are not null this property should have an instance
    public MyEntityRule Rule { get; set; }

    public bool HasRule
    {
        get { return this.Rule != null; }
    }
}

public class MyEntityRule
{
    public int MaxCount { get; set; }

    public int MinSpace { get; set; }
}

Problem?

Mapping fields to my class is a problem. I would like to directly display the internal properties of a class from a flat result set that comes from a data table (above).

I set MapFieldAttributethe class level settings (as shown in the top code), but my rules are always null. Suppose part of the problem is that this internal property of the class must be created first for assignment, because all BLToolkit examples use invisible internal objects. But in my case, I do not want to create an instance of it, if it should be null(most of the time it will be null).

How to do it?

+3
2

BLToolkit - ( , ).

, , .

, , NoInstanceAttribute. , . :

[MapField("MaxCount", "Rule.MaxCount")]
[MapField("MinSpace", "Rule.MinSpace")]
public class MyEntity
{
    public int Id { get; set; }

    public string Name { get; set; }

    public string Description { get; set; }

    [NoInstance] // this will make it work
    public MyEntityRule Rule { get; set; }

    public bool HasRule
    {
        get { return this.Rule != null; }
    }
}

, , , .

+3

BLToolkit MyEntityRule. ..

0

All Articles