Open AlexLook opened 5 years ago
@AlexLook sorry for really late responce, but projet is suspended.
Speaking about your case it is really strange, if no factories are used objects would be initialized with default constructors. During the mapping only primitive properties are set, so null
value could not be set for the ItemType.ItemGroup
property, so i'm confused little bit.
I can advice you trying to specify more detailed mapping configuration with MapFieldAttibute
:
[Serializable]
public class ItemGroup {
public int Id { get; set; }
public string Name { get; set; }
}
[Serializable]
public class ItemType {
public int Id { get; set; }
public string Name { get; set; }
[MapField(Format="ItemGroup.{0}"]
public ItemGroup ItemGroup { get; set; } //<--- = null on second call
public ItemType() {
ItemGroup = new ItemGroup();
}
}
[Serializable]
public class Item {
public int Id { get; set; }
public string Name { get; set; }
[MapField(Format="ItemType.{0}"]
public ItemType ItemType { get; set; } // <--- = null on second call
// …
[MapIgnore] public string ItemTypeName { get { return ItemType.Name; } }
[MapIgnore] public string ItemGroupName { get { return ItemType.ItemGroup.Name; } }
// …
public Item() {
ItemType = new ItemType();
}
}
More detailed at: https://github.com/igor-tkachev/bltoolkit/wiki/Mapping.MapFieldAttribute
Hi! Sorry for very bad english. Strange situation. On all project all OK, but some code work wrong/ After second call mapping don't work. For sample come classes:
In ItemRepository:
On code
On first call ShowData() all fields have good data- () return invalid object with null properies. Query in database is correct and return correct data, Behaviour like not called default constructor (without parameters) on ItemType and ItemGroup or broken mapping. In other parts of program all correct, but two or three methods is broken.
(Item.ItemType != null, Item.ItemType.ItemGroup != null)
, but after second and next callsItem.ItemType=null and ItemType.ItemGroup =null
, but in database all OK. Second and next calls db.ExecuteListBLToolkit last version. .NetFramework 4.0.