Monthly Archives: December 2011

Vermont IT Jobs: SysAdmin at NRG Systems in Hinesburg (a cool company…c’mon do it!)

clip_image002

http://www.nrgsystems.com/
Hinesburg, Vermont

Desktop/Systems Administrator

Job Description

Key Focus

The Desktop/Systems Administrator is responsible for providing first line support to NRG’s information technology users; assuring that user’s IT resources are performing as required. This individual helps users achieve their goals by providing excellent customer service for IT issues/requests, while at the same time assuring the integrity and security of NRG’s information resources.

The Desktop/Systems Administrator will report to the Information Technology Manager and will work with the information technology team to achieve the objectives of the department that are aligned with the company strategic goals.

Primary Responsibilities

  • Manage NRG’s IT Help Desk ticket system by monitoring ticket submission, resolving tickets that fall within the Desktop Administrator job responsibilities, and assigning other tickets to appropriate individuals within the IT department.
  • Resolve user requests for problem resolution regarding desktop hardware, printers and other peripherals, e-mail, MS Office applications and other supported desktop applications, internet/intranet access, in a timely and professional manner.
  • Coordinate the procurement, provisioning, and management of new desktop/laptop computers, printers, A/V equipment, and desktop application licenses to support current and new users.
  • Assure that NRG’s spam, virus, and malware protection is functioning at optimal level.
  • Manage user accounts and provide IT orientation to new employees.
  • Monitor server backup performance, assure proper backup tape storage and rotation, and identify issues that require resolution.
  • Purchase and install new versions of desktop software to maintain currency.
  • Utilize VMWare Virtual Center to support the Network Administrator in managing and maintaining the server and network environment.

Qualifications

  • 4-year degree in computer science, software engineering, or related field
  • 3+ years IT experience with hardware and software support
  • Exceptional communication and teamwork skills.
  • Excellent analytical and problem resolution skills.
  • Excellent organizational skills.
  • Ability to work independently, and prioritize multiple tasks
  • Demonstrated knowledge of desktop/laptop hardware repair for common issues such as hard drive replacement, memory replacement, etc
  • Demonstrated knowledge of Windows XP, Windows 7, Windows Server, VMWare Virtual Center, SQL Server, Active Directory, IIS, Linux.
  • Microsoft certifications a plus
  • Experience in a manufacturing environment a plus

Oracle Releases Provider with EF 4 Support (but not really EF 4.1 and EF4.2)

Oracle has finally released it’s version of ODP.NET that supports Entity Framework for use in production environments.

This is great news for many developers! 

And they report that this release supports EF 4.1 and EF 4.2. That should mean Code First and DbContext but thanks to Frans Bouma sending me the limitations doc (that is part of the installation ) we can see that they aren’t! Too bad.

7. ODP.NET 11.2.0.3 does not support Code First nor the DbContext APIs.

So, that means “not really EF 4.1 and EF 4.2 support” in my opinion. But they told us already that Code First & DbContext weren’t going to make it in. So it was just the momentary surprise of misunderstanding their meaning about EF4.1 & 4.2 support that deflated me a bit. 😉

Howver…I imagine Code First and DbContext are still leading edge for the types of big corporations that use Oracle. The core EF 4 support is a big deal.

I’ll follow up with Oracle for clarification.

More from Oracle (including downloads) here: http://www.oracle.com/technetwork/topics/dotnet/whatsnew/index.html

Note: They’ve updated the what’s new page to say "Code First is not supported." That’s helpful. Be sure that even thought it’s not mentioned there, EF 4.1/4.2 DbContext API is not supported either.

EMail Q&A: What about Entity SQL and why direct DB access?

I received this pair of questions about EF in email and thought I would share the questions and my reply.

Q:

I’ve read some articles about Code First, I’ve tried to do some samples and I’m going to read you last book.

I’m surprised about 2 issues. The first is that it’s possible to write native SQL code (with context.Database.ExecuteSqlCommand and context.Database.SqlQuery methods) and the second is that I’ve not been able to use EntitySQL or Query Builder Methods.

Now, the idea of EF was create a model, operate with objects and use a common language (EntitSql) to interact with "some" databases. But now? We are coming back? Yes, we can use Linq2Entities and SaveChanges but I don’t understand the philosophy of these opened doors upon the database.

I’m wrong?

What’s your idea?

My A:

Dbcontext doesn’t replace ObjectContext. It just makes it easier for devs to access the most common things.

You can still use ObjectContext. You can even use DbContext and access ObjectContext functions when you need to.

Entity SQL was created before the data team knew about LINQ. You can express most queries with LINQ and it works with any EF-compliant database provider, just as ESQL does.

The direct database access command features are a "backdoor" that devs asked for. It should be used only on rare occasions when you need to access something in the database that is not part of the model.

Use Projections and a Repository to Fake a Filtered Eager Load

Entity Framework’s Include method which eager loads related data in a query does not allow sorting and filtering. People ask for this feature frequently.

There is a way around the problem,  I wrote about it in  the June Data Points column in MSDN Magazine (Loading Related Data: http://msdn.microsoft.com/en-us/magazine/hh205756.aspx) but since I just saw another comment on twitter about this, I thought I would stop working on Chapter 7 of the DbContext book that is already delayed and write a quick blog post about using a projection instead.

One caveat…you cannot do this if you have a long running context and you want the objects to remain attached to the context. If there are other related entities in the context, the context will always give them to you. More on this at the end of the post.

Okay, today’s model will be based on a roads and trees on that road. I need some type of guide because we’ve been socked in with fog for two days and I can barely see the trees across my road.

We’ll have two classes (and no I’m not trying to rub in the fact that we don’t have geo support yet, but it’s coming in .NET 4.5.)

public class Tree
  {
    public int Id { get; set; }
    public string Description { get; set; }
    public decimal Lat { get; set; }
    public decimal Long { get; set; }
    public int RoadId { get; set; }
  }
  public class Road
  {
    public Road()
    {
      Trees = new List<Tree>();
    }
    public int Id { get; set; }
    public string Name { get; set; }
    public string Town { get; set; }
    public List<Tree> Trees { get; set; }
  }

The way loading works in Entity Framework is an all or nothing scenario with one exception.

The DbContext lets you do a filter in an explicit load (i.e. after the root is already in memory). Here’s a passing test which loads only maple trees and checks to see that the count of non-maple trees is NOT greater than 0.

(MyInitializer seeds the database with one road that has three related Trees (a maple, a maple and a pine)).

    [TestMethod()]
    public void CanFilterOnExplicitLoad()
    {
      Database.SetInitializer(new MyInitializer());
      var context = new DataAccess();
      var road = context.Roads.FirstOrDefault();
      context.Entry(road).Collection(r => r.Trees)
        .Query().Where(t => t.Description.Contains("Maple"))
        .Load();
      Assert.IsFalse(context.Trees.Local
.Where(t=>!t.Description.Contains("Maple"))
.Count()>0);
    }

But that’s beside the point, since the question is about eager loading.

You can’t filter when eager loading with Include.

But you can get the results you want eagerly if you project.

  [TestMethod()]
    public void CanFilterOnProjection()
    {
      Database.SetInitializer(new MyInitializer());
      var context = new DataAccess();
      var road = context.Roads
        .Select(r=>new{
          r,
          r.Trees.Where(t=>t.Description.Contains("Maple")})
        .FirstOrDefault();
      Assert.IsFalse(context.Trees.Local
.Where(t => !t.Description.Contains("Maple"))
.Count() > 0); } }

That’s nice but whine whine whine, I returned an anonymous type.

If you use a repository, you can hide that.

  public class DumbRepositoryButGoodEnoughForThisDemo
  {
    DataAccess _context=new DataAccess();

    public List<Road> GetRoadsWithFilteredTrees(string treeFilter)
    {
      var roadAndTrees = _context.Roads
       .Select(r=>new{
          Road=r,
          Trees=r.Trees.Where(t=>t.Description.Contains("Maple"))})
        .ToList();
      return roadAndTrees.Select(rAt=>rAt.Road).ToList();
    }
  }

When I return the list of roads from the projection, the Trees will be attached thanks to the context recognizing the relationships.

Here’s another test that does pass:

   [TestMethod()]
    public void RepositoryFilteredRoadsReturnsRoadWithTrees()
    {
      Database.SetInitializer(new MyInitializer());
      var rep = new DumbRepositoryButGoodEnoughForThisDemo();
      var roads = rep.GetRoadsWithFilteredTrees("Maple");
      Assert.IsTrue(roads.FirstOrDefault().Trees.Any());
      Assert.IsFalse(roads.FirstOrDefault()
.Trees
.Where(t => !t.Description.Contains("Maple"))
.Count() > 0); }

And a screenshot as further proof:

projection 

Scenario When This May Not Work As Expected

As Brian points out in the comments, there is one BIG draw back that is also a problem with the filtered explicit load. If there are already related entities tracked by the context, they will automatically be attached to any related entity in the context. That means if the Pine tree was already being tracked then as long as the Road is attached to the context, it will see ALL of the related trees in the context, including the Pine that was already there.

If you are using a pattern where you have a short-lived context that is instantiated just to execute the query, then it’s not a problem. Most of my architectures are like this. But if you are writing a Windows Form or WPF form and have a context that hangs around, you could run into this problem.

You’ll never avoid the problem when the entities are attached to the context.

But here’s a twist on the repository method that will return disconnected objects from a context that is managing multiple object.

   public List<Road> GetDisconnectedRoadsWithFilteredTrees(string treeFilter)
    {
      var roadAndTrees = _context.Roads.AsNoTracking()
       .Select(r => new
       {
         Road = r,
         Trees = r.Trees.Where(t => t.Description.Contains("Maple"))
       })
        .ToList();

      var rt = new List<Road>();
      foreach (var r in roadAndTrees)
      {
        r.Road.Trees.AddRange(r.Trees);
      }
      return roadAndTrees.Select(rAt => rAt.Road).ToList();
    }