Archive

Archive for May 22nd, 2012

Linq for Entity Join Query – Entity Framework

May 22nd, 2012 No comments

The Problem

You have a parent/child table structure in your database that looks like the table structure outlined below.

You have used the EntityFramework or Linq to SQL to build your data access layer.

Now you want to write a method using linq as follows:

public List<Child> GetChildren(string parentName)

The database

Create Table Parent (
  Id int identity(1,1) NOT NULL,
  ParentName varchar(50) NOT NULL,
  CONSTRAINT PK_Parent Primary Key Clustered (
    Id Asc
  )
);

Create Table Child (
   Id int identity(1,1) NOT NULL,
   ParentId int NOT NULL,
   ChildName varchar(50) NOT NULL,
   CONSTRAINT PK_Child Primary Key Clustered (
    Id Asc
  )
)

Obviously I would have foreign keys between parent and child.. you get the idea, this is your basic run of the mill one to many, parent child relationship.

In SQL

To get a list of all the children in sql your query would look something like:

select c.*
from Parent p 
    inner join Child c on c.ParentId = p.Id
Where p.ParentName = @searchString -- where @searchString is a variable 

The Method

I looked around the web to find a simple example of how to do this and I could not find one, that explained how to do an easy join syntax between two tables.

After much trial and error I came up with this:


public List<Child> GetChildren(string parentName)
{
    List<Child> children = null;

    using (FrameworkDb dbContext = new FrameworkDb())
    {
        children = (from c in dbContext.Children
                    join p in dbContext.Parent.Where(p => p.ParentName == parentName)
                    on new { PID = c.ParentId } equals new { PID = p.Id }
                    select c).ToList();
    }

    return children;
}

VN:F [1.9.22_1171]
Rating: 8.2/10 (6 votes cast)

Categories: c#, Code Tags:

ApplicationPoolIdentity find the user account

May 22nd, 2012 No comments

The Problem

How do you find the ApplicationPoolIdentity Account?

Under IIS 7 you have the ability to set the user account that the Application Pool will run under. By Default this appears to be a setting called “ApplicationPoolIdentity”.

So if you need to provide access for this user to a local system resource how do you find the user account when you are searching in the security tab?

The Answer

When the application pool is created a new user account is created with the name of the Application Pool.
This account is created on the local machine in the format of:
IIS AppPool\AppPoolName – where AppPoolName is the name of your application pool

So for example the DefaultAppPool user can be found by searching for:
IIS AppPool\DefaultAppPool

Application Pool Identify - prior to resolve

When Resolved

Application Pool Identity Resolved

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)

Categories: ASP .Net, OS Tags: