views:

29

answers:

1

I've created a business layer with a database model to be used in an ASP.NET application. I've used Linq To SQL Classes in Windows Forms before but using ORMs in per-request web applications is foreign to me. I've a few things I couldn't figure out and I'd appreciate if anyone give me any insight..

My BLL has static methods like GetRecord() or UpdateRecord(). Each one of these methods creates a new ObjectContext instance, destroyed after unit of work. I don't have any HttpContext.Current.Items cache implementation.

I'm using EF .NET 3.5.

  1. I've created a pre-generated view (Model.View.cs) and added it to my solution. Is this all I have to do to use it? Also do I need to publish csdl, msl and ssdl files with my dll?

  2. Is precompiling queries bad for ASP.NET applications? I have like only one or two queries for any ASPX page and very rarely a select query used twice in the same page. Will it slow down the application if precompile my queries? I wonder if a precompile made by Session A would be useful for Session B?

  3. I've created the following method to update a record in ASP.NET page and I wonder if it is a good way to do it:

    ASP.NET gets the record(Entity) using BLL.GetRecord()
    Updates any values
    Sends updated record to BLL.Update()
    BLL.Update() checks if the record exists
    Uses context.ApplyPropertyChanges() to update the record

  4. I've red a few entity framework performance charts and in every one of those charts there are two different statistics for queries: first run and the second run. Since I work with unit-of-work type of design, will my queries never see second runs?

Thanks.

+1  A: 
  1. You need the CSDL, etc., either as files or resources. View pre-generation helps with performances, but doesn't relieve you of the need to include EDMX in some form.
  2. No.
  3. OK as far as it goes. Hard to say more without seeing code.
  4. It depends. This post should help.
Craig Stuntz
Thanks a lot Craig. I'd like to clear a few things if you please: 1. I have an edmx in my project with build action:EntityDeploy. Do I still need to have csdl etc next to my dll when I publish? 2. so precompiling queries aren't bad for ASP.NET applications am I right? precompiling doesn't do any good between sessions of different concurrent users? no global cache or anything like that?
Armagan
1. You need to either (a) deploy those files with your assemblies or (b) change their build actions to embedded resource and [change the EF connection string to match](http://blogs.teamb.com/craigstuntz/2010/08/13/38628/) 2. Precompiling is helpful and helps with current users. Scope is up to you -- you choose the scope when you store the reference to the compiled query.
Craig Stuntz