DynamicModuleManager returning duplicates
Hi,
We recently upgrade to Sitefinity 7.2 and now custom content types we had created when we were using Sitefinity 6.3 are returning duplicates. We inspected the database and noticed that every item has 2 rows associated with it, and the GUID's differ only slightly. e.g. 2AE63F0D-3E54-6B96-8484-FF0000E1ED88 and 34E63F0D-3E54-6B96-8484-FF0000E1ED88. The 2 rows contain the exact same data. We are not sure if this is by design or not. Regardless, most of the code we have in place is now showing duplicates.
Any idea why this might be?
Example code getting all the items of a particular content type:
DynamicModuleManager dmm = DynamicModuleManager.GetManager();
Type locationType = TypeResolutionService.ResolveType(HealthwaysConstants.CONTENT_TYPE_LOCATION);
var locs = dmm.GetDataItems(locationType).Select(dc =>
new
Location
Name = dc.GetValue<
string
>(NAME),
Address = dc.GetValue<
string
>(ADDRESS),
City = dc.GetValue<
string
>(CITY),
State = dc.GetValue<
string
>(STATE),
Zip = dc.GetValue<
string
>(ZIP),
Latitude = dc.GetValue<
decimal
?>(LATITUDE),
Longitude = dc.GetValue<
decimal
?>(LONGITUDE)
).ToList();
rptResults.DataSource = locs;
rptResults.DataBind();
Thanks,
Dan
Hi Dan,
Yes, this is by design. Every item is stored as a Master and there is also a Live version.
If you adjust your code like this, you will get only the Live versions:
DynamicModuleManager dmm = DynamicModuleManager.GetManager();
Type locationType = TypeResolutionService.ResolveType(HealthwaysConstants.CONTENT_TYPE_LOCATION);
var locs = dmm.GetDataItems(locationType).Where(x => x.Status == ContentLifecycleStatus.Live).Select(dc =>
new
Location
Name = dc.GetValue<
string
>(NAME),
Address = dc.GetValue<
string
>(ADDRESS),
City = dc.GetValue<
string
>(CITY),
State = dc.GetValue<
string
>(STATE),
Zip = dc.GetValue<
string
>(ZIP),
Latitude = dc.GetValue<
decimal
?>(LATITUDE),
Longitude = dc.GetValue<
decimal
?>(LONGITUDE)
).ToList();
rptResults.DataSource = locs;
rptResults.DataBind();
You can find more information here: http://docs.sitefinity.com/for-developers-query-master-and-live-versions
Best,
Daniel