Extending Entities

Posts   
 
    
Maxus
User
Posts: 76
Joined: 04-Aug-2006
# Posted on: 18-Dec-2007 03:21:58   

Hi LLBLGEN People!

I had a couple simple questions:

  1. I would like to extend the entities from LLBLGEN in my business layer e.g.:

UserEntity -> MyUserEntity LLBLGEN -> Business layer

Save, insert, delete works great until I try to fetch a collection:


Collection<MyUserEntity> Users = new Collection<MyUserEntity>();

using (CustomDataAccessAdapter Adapter = new CustomDataAccessAdapter(null))
{
      Adapter.FetchEntityCollection(Users, null);
}

return Users;

Returns the exception: "entityToAdd isn't of the right type" The custom adapter simply overrides a couple save methods to add audit information. So I don’t think it has anything to do with that, but i can post the code if it will help.

  1. Can I create a collection class inherited from the entitycollection<> class to use in my business layer, are the any issues with doing that?

Thanks Alex

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 18-Dec-2007 05:24:13   

Hi Alex,

First of all, we like to know how you have to inherit everything. I think this is not always necessary. Have you read LLBLGenPro Help - Using generated code - Adding your own code to the generated classes ?

Returns the exception: "entityToAdd isn't of the right type" The custom adapter simply overrides a couple save methods to add audit information. So I don’t think it has anything to do with that, but i can post the code if it will help.

That is coz (maybe) the entityFactory used (or not used). Could you please attach your MyUserEntity class and EntityFactory used?

BTW, Do you know about new Auditing feature of LLBLGen v2.5?

David Elizondo | LLBLGen Support Team
Maxus
User
Posts: 76
Joined: 04-Aug-2006
# Posted on: 18-Dec-2007 05:43:38   

Hi David,

It is basically and experiment using the WCF services, I'm trying to avoid having references to LLBLGEN in the PL layer as well as adding custom properties and methods to the entities.

At this stage the MyUserEntity simply contains:


namespace NameSpace
{
    /// <summary>
    /// Inherited UserEntity.
    /// </summary>
    /// 
    [Serializable]
    public class User : UserEntity
    {
        /// <summary>
        /// Return the users full name.
        /// </summary>
        public string FullName
        {
            get { return string.Format("{0} {1}",this.FirstName, this.LastName); }
        }
    }
}

In the code above I didn't specify a entityFactory, do you want the userEntitiy's factory code?

I know all about the auditing features of LLBLGEN (played with them a fair amount), Our code was developed using 2.0 before it was available. We may look at switching, but it looks a little like overkill compared to what we are currently using.

Thanks A

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-Dec-2007 11:19:13   
  1. Can I create a collection class inherited from the entitycollection<> class to use in my business layer, are the any issues with doing that?

Why do you want to do this? Please note that Co-variance is not supported in C# and VB.NET don't support co-variance (List<string> doesn't derive from List<object>)

Maxus
User
Posts: 76
Joined: 04-Aug-2006
# Posted on: 19-Dec-2007 00:23:57   

Hi Walaa,

I'm aware of how the issues of inheriting from generic types. What I would like to do is create a collection class in my business layer I can use with LLBLGen like the entity collection, that i can pass to my PL without need to have references to the LLBLGEN libraries, as well as add a couple features for handling and reporting user errors.

Thanks A

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 19-Dec-2007 07:55:36   

I'm aware of how the issues of inheriting from generic types. What I would like to do is create a collection class in my business layer I can use with LLBLGen like the entity collection, that i can pass to my PL without need to have references to the LLBLGEN libraries

Seems to me that you want to use a DTO, coz anything else that will inherit from LLBLGen Pro objects will require you to reference the LLBLGen libraries in the PL. Maybe you need to try using dataTables, or some custom classes which you can produce by projections.