Friday 6 May 2011

ASP.Net Social Networking - Fisharoo: Inconsistent Connection class

In one post, the Connection class is listed like this:

using System.Configuration;
using System.Linq;
using System.Data.Linq;
namespace Fisharoo.FisharooCore.Core.DataAccess.Impl
{
    public class Connection
    {
        public static FisharooDataContext GetContext()
        {
            FisharooDataContext fdc = new FisharooDataContext
               (ConfigurationManager.ConnectionStrings
               ["Fisharoo"].ToString());
            return fdc;
        }
    }
}

In another listing, it is like this:

using System;
using System.Configuration;
using System.Linq;
using System.Data.Linq;
using System.Xml;
using Fisharoo.FisharooCore.Core.Domain;
using Fisharoo.FisharooCore.Properties;
using StructureMap;
namespace Fisharoo.FisharooCore.Core.DataAccess.Impl
{
    public class Connection
    {
        public FisharooDataContext GetContext()
        {
            string connString = "";
            //logic to retrieve your connectionString
            FisharooDataContext fdc = new
            FisharooDataContext(connString);
            return fdc;
        }
    }
}
The other issue is that the code doesn't even compile...I get the error:

Error    6    'Fisharoo.FisharooCore.Domain.FisharooDataContext' does not contain a constructor that takes 1 arguments    ....trunk\source\FisharooCore\DataAccess\Impl\Connection.cs    16    39    FisharooCore

So i deleted the LINQ to SQL file 'Fisharoo.dbml' and then performed 'Add New Item...' from the Solution context menu to see if it would somehow magically create a new constructor which takes the ConnectionString as an argument...

I then got this...notice how there is no Fisharoo.cs file (yet):


I then added all the Tables via Server Explorer. 

Removed all the Relationships on the LINQ Object Relational Designer surface (as recommended in the book) and clicked Save.

Still no Fisharoo.cs file - perhaps this is a good thing?

Going into the Class View, I can now see all the relevant Entity Classes that  Visual Studio has generated for me...YIPPEE!!!

However...I have some Domain naming issues. All the source code references in the book go by the convention:

"Fisharoo.SOME_DOMAIN.SOME_SUB_DOMAIN.Class"

However, I've named all my projects without the "Fisharoo" prefix, simply because all the "SOME_DOMAINS" in the book are prefixed with "Fisharoo" anyway...eg FisharooCore, FisharooWeb...etc.

So, i'll have to either to check everything out and rename my projects to suit the convention...which ideally i would like to do as it would then be consistent with the book and also follow Naming Conventions i found earlier last month...

OR
Just update the namespace references within all the referencing classes...an easy and not so ideal fix.

No comments:

Post a Comment