Hi, firstly I apologise if this has been asked before but I have spent
many hours pulling my hair out trying to get this to work and haven't
been able to find a solution.
My scenario:
Latest code from SVN trunk
SQL Server 2005
Web App
using HttpApplication to initialise AR.
Code:
public void Application_OnStart()
{
IConfigurationSource source =
ConfigurationManager.GetSection("activerecord") as
IConfigurationSource;
ActiveRecordStarter.Initialize(typeof
(DomainLookup).Assembly, source);
}
public HttpRequestScope()
{
BeginRequest += new EventHandler(OnBeginRequest);
EndRequest += new EventHandler(OnEndRequest);
}
public void OnBeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Items.Add("ar.sessionscope", new
SessionScope(FlushAction.Never));
}
public void OnEndRequest(object sender, EventArgs e)
{
try
{
SessionScope scope = HttpContext.Current.Items
["ar.sessionscope"] as SessionScope;
if (scope != null)
scope.Dispose();
}
catch(Exception ex)
{
HttpContext.Current.Trace.Warn("Error", "EndRequest: "
+ ex.Message, ex);
}
}
My Problem:
I need to hold my object in session (currently Inproc and state
server), as the form is quite complicated and involves many ajax
methods (ExtJS)
How can I create an object using .Find() method, detach the object
using .Evict() and store it in HttpContext.Session, then sometime
later re-join the object to the current ISession?
Currently, when I call .SaveAndFlush() on the object I am getting
updates for every field and for every item in related HasMany
collections.
I'm assuming this is because the object has lost the state of the
previous values. Debugging revealed the previous values collection to
be null in the OnFlushDirty callback.
Is this normal behaviour? I can probably live with the base objects
fields being updated, but I can't allow every item in all related
collections to be updated everytime.
Any help much appreciated...
The code for my entities...
Code:
[ActiveRecord("Account", Lazy = true)]
[Serializable]
public class Account : Entity<Account>
{
[PrimaryKey(PrimaryKeyType.Native, Column = "IDAccount")]
public override int Id { get; set; }
[Version("Revision")]
public virtual int Revision { get; set; }
//[Timestamp("Revision")]
//public virtual DateTime Revision { get; set; }
[Property(Length = 80), ValidateIsUnique("The name has already
been used for another account")
, ValidateNonEmpty, ValidateLength(0, 30)] //
public virtual string Name { get; set; }
[Property, ValidateNonEmpty]
public virtual AccountType Type { get; set; }
[BelongsTo("IDAccountStatus"), ValidateNonEmpty]
public virtual AccountStatus Status { get; set; }
....
#region Contacts
public virtual void AddContact(Contact contact)
{
contact.Account = this;
_contacts.Add(contact);
}
private ISet<Contact> _contacts = new HashedSet<Contact>();
[HasMany(Lazy = true, Cascade =
ManyRelationCascadeEnum.SaveUpdate, Inverse=true)]
public virtual ISet<Contact> Contacts
{
get { return _contacts; }
set { _contacts = value; }
}
#endregion
}
[Serializable]
[ActiveRecord("Contact")]
public class Contact : Entity<Contact>
{
[PrimaryKey(PrimaryKeyType.Native, Column = "IDContact")]
public override int Id { get; set; }
[Version("Revision")]
public virtual Int32 Revision { get; set; }
[BelongsTo("IDAccount", Cascade=CascadeEnum.None )]
public virtual Account Account { get; set; }
[Property(Length = 32), ValidateNonEmpty]
public virtual string Title { get; set; }
[Property(Length = 80), ValidateNonEmpty]
public virtual string Firstname { get; set; }
[Property(Length=80), ValidateNonEmpty]
public virtual string Lastname { get; set; }
[Property(Length = 120), ValidateEmail]
public virtual string Email { get; set; }
[Property(Length = 32), ValidateRegExp(@"^(\(?\+?[0-9]*\)?)?
[0-9_\- \(\)]*$")]
public virtual string Telephone { get; set; }
[Property(Length = 32), ValidateRegExp(@"^(\(?\+?[0-9]*\)?)?
[0-9_\- \(\)]*$")]
public virtual string Facsimile { get; set; }
[Property(Length = 32), ValidateRegExp(@"^(\(?\+?[0-9]*\)?)?
[0-9_\- \(\)]*$")]
public virtual string Mobile { get; set; }
[Property(Length = 12), ValidateRegExp(@"^(\(?\+?[0-9]*\)?)?
[0-9_\- \(\)]*$")]
public virtual string Extension { get; set; }
[Property(Length=48)]
public virtual string JobTitle { get; set; }
...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---