You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
[Serializable]publicclassItemGroup{publicintId{get;set;}publicstringName{get;set;}}[Serializable]publicclassItemType{publicintId{get;set;}publicstringName{get;set;}publicItemGroupItemGroup{get;set;}<---=null on secondcall
public ItemType(){ItemGroup=newItemGroup();}}[Serializable]publicclassItem{publicintId{get;set;}publicstringName{get;set;}publicItemTypeItemType{get;set;}// <--- = null on second call// …[MapIgnore]publicstringItemTypeName{get{returnItemType.Name;}}[MapIgnore]publicstringItemGroupName{get{returnItemType.ItemGroup.Name;}}// …publicItem(){ItemType=newItemType();}}
In ItemRepository:
publicclassItemRepository{privateconststringGetItemsQuery=@" SELECT i.Id AS [Id], i.Name AS [Name], t.Id AS [ItemType.Id], t.Name AS [ItemType.Name], g.Id AS [ItemType.ItemGroup.Id], g.Name AS [ItemType.ItemGroup.Name] FROM Items i JOIN ItemTypes t JOIN ItemGroups g ON t.GroupId = g.Id ON i.TypeId = t.Id WHERE g.Id = @groupId AND t.Id = @typeId";publicList<Item>GetItems(intgroupId,inttypeId){// <- on second call this method marked fields is nullusing(vardb=newDbManager()){returndb.SetCommand(GetItemsQuery,db.Parameter("@groupId",groupId),db.Parameter("@typeId",typeId)).ExecuteList<Item>();}}}
On first call ShowData() all fields have good data (Item.ItemType != null, Item.ItemType.ItemGroup != null), but after second and next calls Item.ItemType=null and ItemType.ItemGroup =null, but in database all OK. Second and next calls db.ExecuteList() 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.
BLToolkit last version. .NetFramework 4.0.
The text was updated successfully, but these errors were encountered:
@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]publicclassItemGroup{publicintId{get;set;}publicstringName{get;set;}}[Serializable]publicclassItemType{publicintId{get;set;}publicstringName{get;set;}[MapField(Format="ItemGroup.{0}"]publicItemGroupItemGroup{get;set;}//<--- = null on second callpublicItemType(){ItemGroup=newItemGroup();}}[Serializable]publicclassItem{publicintId{get;set;}publicstringName{get;set;}[MapField(Format="ItemType.{0}"]publicItemTypeItemType{get;set;}// <--- = null on second call// …[MapIgnore]publicstringItemTypeName{get{returnItemType.Name;}}[MapIgnore]publicstringItemGroupName{get{returnItemType.ItemGroup.Name;}}// …publicItem(){ItemType=newItemType();}}
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
(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.ExecuteList() 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.BLToolkit last version. .NetFramework 4.0.
The text was updated successfully, but these errors were encountered: