How to use

Examples

About T4 Templates

T4 Templates

Lazy load on collections

If an entity property is declared as ICollection and can be mapped to an OpenErp property (name should match property name or a OpenErpMap attribute should be declared), the property is filled with a collection of OpenErpSet that will load related entities on access.

For example:

POCO classes:
    [OpenErpMap("ir.model")]
    public class Model
    {

        [OpenErpMap("id")]
        public int Id { get; set; }

        [OpenErpMap("field_id")]
        public ICollection<Field> Fields { get; set; }
    }

[OpenErpMap("ir.model.fields")]
    public class Field
    {
        [OpenErpMap("name")]
        public string Name { get; set; }
    }



OpenErpNet will detect that ICollection property Fields are a OpenErpProperty and will fill Fields property with an OpenErpSet collection. When collection is accessed, it will load Field entities from OpenErp.

IEnumerable<Model> models;
            OpenErpService openErpService = new OpenErpService(OpenErpServer, OpenerpDataBase, OpenerpUser, OpenerpPass);
            models = openErpService.GetEntities<Model>(e => e.Name.Equals("Models"));
            Model model = models.FirstOrDefault();
            int fields = model.Fields.Count();


You can use include extensión method from Jlob.OpenErpNet library to force entity load.
IEnumerable<Model> models;
            OpenErpService openErpService = new OpenErpService(OpenErpServer, OpenerpDataBase, OpenerpUser, OpenerpPass);
            models = openErpService.GetEntities<Model>(e => e.Name.Equals("Models")).Include(e => e.Fields);
            Model model = models.FirstOrDefault();


Last edited Apr 14, 2014 at 8:46 PM by Jlob, version 7