Validators don't (seem to) work in MultiView view.
May be due to Ajax v1 & validators see above.
Monday, 12 March 2007
Thursday, 8 March 2007
NHibernate Flush before Query
Was having a problem with following:
This is caused by the FlushMode of the session be set to Auto. When set to auto NHibernate will sometimes flush the persistent obejct prior to performing a query.
There are a few solutions to this:
- Start Session
- Read object/record (presentation layer)
- Update record/object im memory (presentation layer)
- Run query to check changes valid (biz layer).
- If 4 ok commit changes inside transaction (biz layer)
- End session
This is caused by the FlushMode of the session be set to Auto. When set to auto NHibernate will sometimes flush the persistent obejct prior to performing a query.
There are a few solutions to this:
- Perform updates to object after query (not applicable in this case due to layers)
- Disconnect object prior to updating (Evict)
- Change FlushMode to Commit
Tuesday, 6 March 2007
Error on DataBind() of DropDownList:, invalid SelectedValue
Getting error:
The SelectedValue before the databind is set to "" (i.e. blank string)
The error occurs because the data being bound does not include a value of "" (blank string).
To fix it:
has a SelectedValue which is invalid because it does not exist in the list of item
The SelectedValue before the databind is set to "" (i.e. blank string)
The error occurs because the data being bound does not include a value of "" (blank string).
To fix it:
- Set AppendDataBoundItems=true for control
- Clear the list prior to databind;
.Items.Clear(); - Add a blank item:
.Items.Add(new ListItem("", "")); - Call
.DataBind();
Monday, 5 March 2007
How to map to a Generic IDictionary
Say you have a standard nHibernate Bag that maps to a IList
C# Definition
public virtual IList<UserGroup> Groups;
nHibernate Mapping
<bag name="UserGroups" table="UserGroup">
<key column="UserID"/>
<one-to-many class="UserGroup"/>
</bag>
You can change this to a IDictionary by changing the IList to a IDictionary in the Business Entity, then change the bag to a map,and adding a index setting to the nHibernate mapping.
So the above would be changed to
C# Definition
public virtual IDictionary<int,UserGroup> Groups;
nHibernate Mapping
<map name="UserGroups" table="UserGroup">
<key column="UserID"/>
<index column="GroupID" type="int"/>
<one-to-many class="UserGroup"/>
</map>
Where of course the index column is the column that you will search on, and the type is the type of the column.
NOTE - The Key Column and the Index column cannot be the same, but then thinking about that it would be pointless because the key value would be the same on all the keys of the dictionary.
C# Definition
public virtual IList<UserGroup> Groups;
nHibernate Mapping
<bag name="UserGroups" table="UserGroup">
<key column="UserID"/>
<one-to-many class="UserGroup"/>
</bag>
You can change this to a IDictionary by changing the IList to a IDictionary in the Business Entity, then change the bag to a map,and adding a index setting to the nHibernate mapping.
So the above would be changed to
C# Definition
public virtual IDictionary<int,UserGroup> Groups;
nHibernate Mapping
<map name="UserGroups" table="UserGroup">
<key column="UserID"/>
<index column="GroupID" type="int"/>
<one-to-many class="UserGroup"/>
</map>
Where of course the index column is the column that you will search on, and the type is the type of the column.
NOTE - The Key Column and the Index column cannot be the same, but then thinking about that it would be pointless because the key value would be the same on all the keys of the dictionary.
NHibernate error loading class
Got the error:
Was caused by an incorrect class="Page" reference in one of the object mapping files.
Could not load type '...Page, SalecoreContent', check that type and assembly names are correct
Was caused by an incorrect class="Page" reference in one of the object mapping files.
Friday, 2 March 2007
nHibernate Get or Load?
Session.Get and Session.Load do very similar things, the difference is.
.Get will return null if a record is not found.
.Save will return an exception if a record is not found, and if it can use a proxy, it will return a proxy, so you won't get the exception until you try to actually use the object.
If you are not sure that a record exists then use .Get and check that the object isn't null.
.Get will return null if a record is not found.
.Save will return an exception if a record is not found, and if it can use a proxy, it will return a proxy, so you won't get the exception until you try to actually use the object.
If you are not sure that a record exists then use .Get and check that the object isn't null.
NHibernate:How do I know a field is dirty?
The problem arose that I needed to know if a field had changed just prior to saving:
The solution seems to be either clear the cache or tell the business object that the field has changed. The clear-the-cache solution was not tried, would have been along the lines of Session.Evict(object).
- Presentation layer reads object/record
- Presentation layer changes object field value
- Presentation layer calls business layer to update the object/record
- Business layer needs to know if a certain field has changed to perform extra processing
The solution seems to be either clear the cache or tell the business object that the field has changed. The clear-the-cache solution was not tried, would have been along the lines of Session.Evict(object).
Subscribe to:
Posts (Atom)