tags:

views:

12

answers:

1

Hello!

I'm using SubSonic 2.1. I ran it against a database and it created all the files seemingly correctly. However, when I went to use one of the classes, the app wouldn't built. I'm making a Windows application, but in the SubSonic file there's a reference to HttpContext.Current.User. Does anyone know why that would happen?

+1  A: 

SubSonic was initially designed to be used within a asp.net application.

However it works very well in a Windows.Forms application. But you need to include System.Web into your project.

Look in the ClassTemplate.aspx: http://github.com/subsonic/SubSonic-2.0/blob/master/SubSonic/CodeGeneration/Templates/CS_ClassTemplate.aspx

if (System.Web.HttpContext.Current != null)
    item.Save(System.Web.HttpContext.Current.User.Identity.Name);
else
    item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);

If the code is executed inside a asp.net webpage it pulls the username from the context and outside gets the username from the current thread.

There is a convention in subsonic that, if your table contains a CreatedBy and ModifiedBy column and you use the item.Save("username") method these columns get's updated, too.

If you change the CS_ClassTemplate.aspx file to not use System.Web and regenerate your DAL you probably won't need the reference to System.Web anymore.

SchlaWiener
Ah, I see! I thought I had broke something, LOL! Thanks!
Darkwater23