Making a Generic Base Class

Posts   
 
    
simon831
User
Posts: 152
Joined: 19-Jan-2006
# Posted on: 14-Jan-2010 14:38:13   

I am designing a new project using LLB...

I will have a 'Manager' layer that sits between a website and the LLB generated code. Most LLB entities have an EntityManager class.

How far will I be able to put generic code in a Manager base class, to stop similar code being repeated in every EntityManager?

For example:

    public static IEntity2 Get(IEntity2 entity2)
    {
        using (DataAccessAdapter adapter = new DataAccessAdapter())
        {
            if (adapter.FetchEntity(entity2))
                entity2.Fields.State = EntityState.Fetched;
            return entity2;
        }
    }

    public static ENTITY Get<ENTITY>(Guid primaryKey) where ENTITY : IEntity2, new()
    {
        ENTITY entity = new ENTITY();
        IList<IEntityField2> pks = entity.PrimaryKeyFields;
        if (!pks[0].DataType.Equals(typeof(Guid)))
            throw new ApplicationException("Attempt to get an entity that does not have a Guid as a primary key.");
        pks[0].ForcedCurrentValueWrite(primaryKey);
        using (DataAccessAdapter adapter = new DataAccessAdapter())
        {
           if (adapter.FetchEntity(entity))
                entity.Fields.State = EntityState.Fetched;
            return entity;
        }
    }
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Jan-2010 02:40:36   

Actually someone wrote that already. Please enter into: Customer Area -> Downloads -> v2.0 -> 3rd Party -> Managers templates and take a look wink That would give some lights on that subject.

David Elizondo | LLBLGen Support Team
simon831
User
Posts: 152
Joined: 19-Jan-2006
# Posted on: 20-Jan-2010 17:21:11   

daelmo wrote:

Customer Area -> Downloads -> v2.0 -> 3rd Party -> Managers templates

Seems good. I get exceptions trying to use them though. I have the latest v2.6. Are these templates just for use with llb v2.0?


Could not find a part of the path 'D:\test\Core\Managers\Base\ManagerBase.cs'.

-----[Core exception]-------------------- at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) at System.IO.StreamWriter.CreateFile(String path, Boolean append) at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize) at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding) at SD.LLBLGen.Pro.LptParser.DotNetTemplateEngine.Perform(IGenerator executingGenerator, ITask taskDefinition, Dictionary2 parameters) at SD.LLBLGen.Pro.ApplicationCore.Tasks.Task.Perform(IGenerator executingGenerator, LogNode parentNode) at SD.LLBLGen.Pro.ApplicationCore.Tasks.TaskGroup.Perform(IGenerator executingGenerator, LogNode parentNode) at SD.LLBLGen.Pro.ApplicationCore.Tasks.TaskGroup.Perform(IGenerator executingGenerator, LogNode parentNode) at SD.LLBLGen.Pro.GeneratorCore.Generator.Start(ITaskGroup tasksToExecute, Project projectDefinition, Language languageToUse, Platform platformToUse, List1 templateBindingsToUse, String templateGroupToUse, ApplicationConfiguration configurationSettings)

simon831
User
Posts: 152
Joined: 19-Jan-2006
# Posted on: 25-Jan-2010 10:52:48   

Do these templates work with v2.6 or just v2.0?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Jan-2010 04:43:45   

Not officially ported to v2.6 but they work well. I tested them. Other people did as well: http://llblgen.com/tinyforum/Messages.aspx?ThreadID=14141

So, please post more information about your problem. I think you are missing something when setup the tasks. Did you follow the steps in the readme file?

David Elizondo | LLBLGen Support Team