Hi i am attahcing the code i wrote:
the first criteria returns 20000 objects and then i modify all the 20000 objects(The date it was updated is important)
THX!!!
Code:
int LocationID=10000019;
EntityContextObj context = new EntityContextObj();
DateTime dt = DateTime.Now.AddDays(-7);
using (ISession session = NHibernateHelper.GetCurrentSession(context))
{
ICriteria criteria = session.CreateCriteria(typeof(ItemData));
criteria.Add(Expression.And(Expression.Eq("OrgID", LocationID), Expression.Gt("TimeStamp", dt)));
criteria.AddOrder(Order.Asc("ItemID"));
IList<ItemData> ItemsList = criteria.List<ItemData>();
//try to join criteria 2 and 3
ICriteria criteria2 = session.CreateCriteria(typeof(SnapShotLocation));
criteria2.Add(Expression.Eq("LocationID", LocationID));
SnapShotLocation SSL = (SnapShotLocation)criteria2.UniqueResult();
SSL.SnapShotDate = DateTime.Now;
ICriteria criteria3 = session.CreateCriteria(typeof(SnapShotItem));
//get all the current Items that r in the DB for this location.
criteria3.Add(Expression.Eq("SnapShotID", SSL));
criteria3.AddOrder(Order.Asc("ItemID"));
IList<SnapShotItem> SnapShotItemsList = criteria3.List<SnapShotItem>();
for (int i = 0; i < ItemsList.Count; i++)
{
SnapShotItemsList[i].ItemQuantity = ItemsList[i].ItemQuantity;
SnapShotItemsList[i].Timestamp = DateTime.Now;
SSL.AddItem(SnapShotItemsList[i]);
session.Evict(ItemsList[i]);
}
session.SaveOrUpdate(SSL);
session.Flush();
}
NHibernateHelper.CloseSession();
}
the Mapping:
Code:
<class name="ItemData" table="PID_PerpetualInventory">
<composite-id>
<key-property name="ItemID" column="ItemID"/>
<key-property name="OrgID" column="LocationID"/>
</composite-id>
<property name="ItemQuantity" column="Quantity" type="double"/>
<property name="CountDate" column="InvCountDate" type="DateTime"/>
<property name="CountAmount" column="InvCountQuantity" type="Double"/>
<property name="Value" column="ItemCost" type="Double"/>
<property name="TimeStamp" column="TimeStamp" type="DateTime"/>
</class>
<class name="SnapShotItem" table="PID_SnapshotItems">
<id name="ItemID">
<generator class="assigned"/>
</id>
<version name="Version" unsaved-value="0"/>
<many-to-one name="SnapShotID" class="SnapShotLocation" column="SnapShotID"/>
<property name="ItemQuantity" column="Quantity" type="double"/>
<property name="CountDate" column="InvCountDate" type="DateTime"/>
<property name="CountAmount" column="InvCountQuantity" type="Double"/>
<property name="ItemCost" type="Double"/>
<property name="Timestamp" type="DateTime"/>
</class>
<class name="SnapShotLocation" table="PID_SnapshotLocation">
<id name="SnapShotID">
<generator class="native"/>
</id>
<version name="Version" unsaved-value="0"/>
<property name="LocationID"/>
<property name="SnapShotDate" type="DateTime"/>
<bag name="Items" inverse="true" cascade="all" optimistic-lock="false">
<key>
<column name="SnapShotID"/>
</key>
<one-to-many class="SnapShotItem"/>
</bag>
</class>
[/code]