Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> Enhancing generated classes?
 

Pages: 1
LLBLGen Pro Runtime Framework
Enhancing generated classes?
Page:1/1 

  Print all messages in this thread  
Poster Message
JKC
User



Location:

Joined on:
25-Jan-2008 22:29:10
Posted:
16 posts
# Posted on: 25-Jan-2008 22:59:17.  
Is is possible to manually add new properties to generated classes? e.g. add a calculated property/field... or do I have to create a class that inherits from a generated class?

Basically, i'd like to use the generated classes as a base and then add to and customize them as necessary.

Can someone provide an example for me?
  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
8138 posts
# Posted on: 26-Jan-2008 01:51:33.  
Hi JKC,

You don't have to inherit from EntityClasses if you don't need that. LLBLGenPro comes with a variety of ways to extend your code.

Please read LLBLGenPro Help - Using the generated code - Adding your own code to the generated classes. and let us know if you still would need some examples. The forum is full of code-snippets, you can also download examples from the Download section of the LLBLGenPro site.

Hope helpful Regular Smiley


David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
JKC
User



Location:

Joined on:
25-Jan-2008 22:29:10
Posted:
16 posts
# Posted on: 28-Jan-2008 14:45:58.  
daelmo wrote:
Hi JKC,

You don't have to inherit from EntityClasses if you don't need that. LLBLGenPro comes with a variety of ways to extend your code.

Please read LLBLGenPro Help - Using the generated code - Adding your own code to the generated classes. and let us know if you still would need some examples. The forum is full of code-snippets, you can also download examples from the Download section of the LLBLGenPro site.

Hope helpful Regular Smiley


Thanks... Where can I find that? (No link)
  Top
JKC
User



Location:

Joined on:
25-Jan-2008 22:29:10
Posted:
16 posts
# Posted on: 28-Jan-2008 14:48:41.  
JKC wrote:
daelmo wrote:
Hi JKC,

You don't have to inherit from EntityClasses if you don't need that. LLBLGenPro comes with a variety of ways to extend your code.

Please read LLBLGenPro Help - Using the generated code - Adding your own code to the generated classes. and let us know if you still would need some examples. The forum is full of code-snippets, you can also download examples from the Download section of the LLBLGenPro site.

Hope helpful Regular Smiley


Thanks... Where can I find that? (No link)


Never mind. I'm a little slow today... got it in the software. I'll check out and let you know, Thanks!


  Top
JKC
User



Location:

Joined on:
25-Jan-2008 22:29:10
Posted:
16 posts
# Posted on: 28-Jan-2008 17:47:57.  
JKC wrote:
JKC wrote:
daelmo wrote:
Hi JKC,

You don't have to inherit from EntityClasses if you don't need that. LLBLGenPro comes with a variety of ways to extend your code.

Please read LLBLGenPro Help - Using the generated code - Adding your own code to the generated classes. and let us know if you still would need some examples. The forum is full of code-snippets, you can also download examples from the Download section of the LLBLGenPro site.

Hope helpful Regular Smiley


Thanks... Where can I find that? (No link)


Never mind. I'm a little slow today... got it in the software. I'll check out and let you know, Thanks!


OK... Got something.

I have my entity class. There are two properties that that entity class has that are a result of two fields in the DB. Only thing is, those two fields need to be calculated via code, not just pulled from the DB and populated. They are always the same calcs.

E.g. when I built the class myself, I set the calcs in the GET...

Now, how do I setup the same thing? E.g. do I remove those fields from the generated classes somewhere and then setup the link via partial class and namespace? Or do I have to create a method(s) that calcs and then set the property(s) to that method?
  Top
JKC
User



Location:

Joined on:
25-Jan-2008 22:29:10
Posted:
16 posts
# Posted on: 28-Jan-2008 17:50:48.  
JKC wrote:
JKC wrote:
JKC wrote:
daelmo wrote:
Hi JKC,

You don't have to inherit from EntityClasses if you don't need that. LLBLGenPro comes with a variety of ways to extend your code.

Please read LLBLGenPro Help - Using the generated code - Adding your own code to the generated classes. and let us know if you still would need some examples. The forum is full of code-snippets, you can also download examples from the Download section of the LLBLGenPro site.

Hope helpful Regular Smiley


Thanks... Where can I find that? (No link)


Never mind. I'm a little slow today... got it in the software. I'll check out and let you know, Thanks!


OK... Got something.

I have my entity class. There are two properties that that entity class has that are a result of two fields in the DB. Only thing is, those two fields need to be calculated via code, not just pulled from the DB and populated. They are always the same calcs.

E.g. when I built the class myself, I set the calcs in the GET...

Now, how do I setup the same thing? E.g. do I remove those fields from the generated classes somewhere and then setup the link via partial class and namespace? Or do I have to create a method(s) that calcs and then set the property(s) to that method?


Or is this where I would take advantage of polymorphism and inheritance?


  Top
JKC
User



Location:

Joined on:
25-Jan-2008 22:29:10
Posted:
16 posts
# Posted on: 28-Jan-2008 19:12:38.  
JKC wrote:
JKC wrote:
JKC wrote:
JKC wrote:
daelmo wrote:
Hi JKC,

You don't have to inherit from EntityClasses if you don't need that. LLBLGenPro comes with a variety of ways to extend your code.

Please read LLBLGenPro Help - Using the generated code - Adding your own code to the generated classes. and let us know if you still would need some examples. The forum is full of code-snippets, you can also download examples from the Download section of the LLBLGenPro site.

Hope helpful Regular Smiley


Thanks... Where can I find that? (No link)


Never mind. I'm a little slow today... got it in the software. I'll check out and let you know, Thanks!


OK... Got something.

I have my entity class. There are two properties that that entity class has that are a result of two fields in the DB. Only thing is, those two fields need to be calculated via code, not just pulled from the DB and populated. They are always the same calcs.

E.g. when I built the class myself, I set the calcs in the GET...

Now, how do I setup the same thing? E.g. do I remove those fields from the generated classes somewhere and then setup the link via partial class and namespace? Or do I have to create a method(s) that calcs and then set the property(s) to that method?


Or is this where I would take advantage of polymorphism and inheritance?


Essentially (this is with methods as opposed to calculated properties) I am trying to do this (where VendorevalQ1, VendorevalQ2, and VendorevalQ3 are fields (properties) of the VendorEvalEntity object that was generated). Unfortunately, its telling me that there is an issue with the GET... Help?

namespace VendorEvaluations.EntityClasses
{
    public partial class VendorEvaluationEntity
    {

     public static int GetVendorEvalTotal()
        {
         int vendorevaltotal;
         vendorevaltotal = Convert.ToInt32(VendorevalQ1) + Convert.ToInt32(VendorevalQ2) + Convert.ToInt32(VendorevalQ3);
         return vendorevaltotal;
        }

        public static string GetVendorEvalRating()
        {
            string vendorevalrating = "";

            if (GetVendorEvalTotal() >= 26)
                {
                    vendorevalrating = "Critical";
                }
                else if ((GetVendorEvalTotal() >= 10) && (GetVendorEvalTotal() <= 25))
                {
                    vendorevalrating = "Material";
                }
                else if ((GetVendorEvalTotal() >= 0) && (GetVendorEvalTotal() <= 9))
                {
                    vendorevalrating = "Minor";
                }
            return vendorevalrating;
  Top
JimFoye
User



Location:
Austin, TX
Joined on:
22-Jun-2004 04:03:11
Posted:
656 posts
# Posted on: 29-Jan-2008 03:16:48.  
For some reason you've declared the methods static, but they are accessing fields.

  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14626 posts
# Posted on: 29-Jan-2008 09:27:03.  
Quote:
its telling me that there is an issue with the GET... Help?

Yeah as Jim said I think it's the static declaration.
If you are getting another error, please post the exact error text.
  Top
JKC
User



Location:

Joined on:
25-Jan-2008 22:29:10
Posted:
16 posts
# Posted on: 29-Jan-2008 14:39:43.  
JimFoye wrote:
For some reason you've declared the methods static, but they are accessing fields.


Thanks. I actually fixed it, there were a couple of things.

My larger question still stands... instead of creating methods, how can I recreate/define the fields as calculated... or can I remove them from the base class and create them via partial class? Will the gen code still work?

e.g. my original issue, I want two of the fields in the class (that have fields in the db for storage) to be fields that are calculated based on other fields of the object. If I were building this from scratch, thats easy. If the gen code built editable classes (instead of the field generator) then it would be easy. But as is... I dont know how to accomplish what I need...


  Top
JKC
User



Location:

Joined on:
25-Jan-2008 22:29:10
Posted:
16 posts
# Posted on: 29-Jan-2008 14:40:22.  
Walaa wrote:
Quote:
its telling me that there is an issue with the GET... Help?

Yeah as Jim said I think it's the static declaration.
If you are getting another error, please post the exact error text.


See above please. Thanks!
  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
8138 posts
# Posted on: 29-Jan-2008 16:36:03.  
Hi Nick,

JKC wrote:

My larger question still stands... instead of creating methods, how can I recreate/define the fields as calculated... or can I remove them from the base class and create them via partial class? Will the gen code still work?

You can create a property at your entity class (via a partial class or via user custom code sections).
For example, I have a EmployeeEntity, that entity has some fields: FirstName, LastName, etc.
I want to have a property bindable that shows the FullName and use it as a Entity property. Well, all I have to do is:
Code:
#region Custom Entity code

// __LLBLGENPRO_USER_CODE_REGION_START CustomEntityCode

public string FullName
{
    get
    {
        return FirstName + " " + LastName;
    }
}

// __LLBLGENPRO_USER_CODE_REGION_END
#endregion

at my EmployeeEntity.cs file, OR
Code:


using System;

using Northwind;
using Northwind.HelperClasses;
using Northwind.FactoryClasses;
using Northwind.RelationClasses;

using SD.LLBLGen.Pro.ORMSupportClasses;

namespace SD.LLBLGen.Pro.Examples.Auditing.EntityClasses
{
    public partial class EmployeeEntity
        {

             public string FullName
             {
                    get
                    {
                         return FirstName + " " + LastName;
                    }
                }
        }
}


at a partial class.


Above property do a in-entity-in-memory concatenation. You also can do a field-level fetch-level expression to fill a new custom field. A bit more work but if that is what you need, you can read this post: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=10287


David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
goose
User



Location:
Central America
Joined on:
06-Aug-2007 18:21:05
Posted:
392 posts
# Posted on: 29-Jan-2008 16:49:10.  
Quote:
My larger question still stands... instead of creating methods, how can I recreate/define the fields as calculated... or can I remove them from the base class and create them via partial class? Will the gen code still work?

e.g. my original issue, I want two of the fields in the class (that have fields in the db for storage) to be fields that are calculated based on other fields of the object. If I were building this from scratch, thats easy. If the gen code built editable classes (instead of the field generator) then it would be easy. But as is... I dont know how to accomplish what I need...


this threads may help you:

http://llblgen.com/TinyForum/Messages.aspx?ThreadID=10349
http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=6254
gansodesoya  Top
JKC
User



Location:

Joined on:
25-Jan-2008 22:29:10
Posted:
16 posts
# Posted on: 29-Jan-2008 17:17:39.  
daelmo wrote:
Hi Nick,

JKC wrote:

My larger question still stands... instead of creating methods, how can I recreate/define the fields as calculated... or can I remove them from the base class and create them via partial class? Will the gen code still work?

You can create a property at your entity class (via a partial class or via user custom code sections).
For example, I have a EmployeeEntity, that entity has some fields: FirstName, LastName, etc.
I want to have a property bindable that shows the FullName and use it as a Entity property. Well, all I have to do is:
Code:
#region Custom Entity code

// __LLBLGENPRO_USER_CODE_REGION_START CustomEntityCode

public string FullName
{
    get
    {
        return FirstName + " " + LastName;
    }
}

// __LLBLGENPRO_USER_CODE_REGION_END
#endregion

at my EmployeeEntity.cs file, OR
Code:


using System;

using Northwind;
using Northwind.HelperClasses;
using Northwind.FactoryClasses;
using Northwind.RelationClasses;

using SD.LLBLGen.Pro.ORMSupportClasses;

namespace SD.LLBLGen.Pro.Examples.Auditing.EntityClasses
{
    public partial class EmployeeEntity
        {

             public string FullName
             {
                    get
                    {
                         return FirstName + " " + LastName;
                    }
                }
        }
}


at a partial class.


Above property do a in-entity-in-memory concatenation. You also can do a field-level fetch-level expression to fill a new custom field. A bit more work but if that is what you need, you can read this post: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=10287


RIGHT... HOWEVER, what if the field that you want to modify already exists in the GENERATED Entity because it was a field in the DB... but rather than this be a standard GET, SET like the rest of the generated, you need it to be a GET only?

e.g. I dont want a NEW field, but modify one that was generated because it exists in my DB to be GET only and do the calcs.


  Top
goose
User



Location:
Central America
Joined on:
06-Aug-2007 18:21:05
Posted:
392 posts
# Posted on: 29-Jan-2008 17:40:52.  
Quote:
RIGHT... HOWEVER, what if the field that you want to modify already exists in the GENERATED Entity because it was a field in the DB... but rather than this be a standard GET, SET like the rest of the generated, you need it to be a GET only?

e.g. I dont want a NEW field, but modify one that was generated because it exists in my DB to be GET only and do the calcs.


In that case yes, when you generate the code you'll get a read only property in the corresponding generated entity.

A tip: if you need to use the calculated field value in your code after the save remember to send the refetchAfterSave parameter in the SaveEntity or SaveEntityCollection methods.
gansodesoya  Top
JKC
User



Location:

Joined on:
25-Jan-2008 22:29:10
Posted:
16 posts
# Posted on: 29-Jan-2008 18:02:06.  
goose wrote:
Quote:
RIGHT... HOWEVER, what if the field that you want to modify already exists in the GENERATED Entity because it was a field in the DB... but rather than this be a standard GET, SET like the rest of the generated, you need it to be a GET only?

e.g. I dont want a NEW field, but modify one that was generated because it exists in my DB to be GET only and do the calcs.


In that case yes, when you generate the code you'll get a read only property in the corresponding generated entity.

A tip: if you need to use the calculated field value in your code after the save remember to send the refetchAfterSave parameter in the SaveEntity or SaveEntityCollection methods.


What I mean is this... I have say a TOTAL field in my DB. The Generator generates this as an INT Property with a GET, SET (we'll call it PROPERTY C). I need to modify this generated GET, SET PROPERTY C to be only GET and be the value of say PROPERTY A + PROPERTY B.

How do I do that?


  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
38048 posts
# Posted on: 29-Jan-2008 21:11:21.  
JKC wrote:
goose wrote:
Quote:
RIGHT... HOWEVER, what if the field that you want to modify already exists in the GENERATED Entity because it was a field in the DB... but rather than this be a standard GET, SET like the rest of the generated, you need it to be a GET only?

e.g. I dont want a NEW field, but modify one that was generated because it exists in my DB to be GET only and do the calcs.


In that case yes, when you generate the code you'll get a read only property in the corresponding generated entity.

A tip: if you need to use the calculated field value in your code after the save remember to send the refetchAfterSave parameter in the SaveEntity or SaveEntityCollection methods.


What I mean is this... I have say a TOTAL field in my DB. The Generator generates this as an INT Property with a GET, SET (we'll call it PROPERTY C). I need to modify this generated GET, SET PROPERTY C to be only GET and be the value of say PROPERTY A + PROPERTY B.

How do I do that?

UNmap the Total field in your entity in the designer: select the field then click 'remove selected field(s)', you don't need it apparently. Now, in the partial class of the entity, you add a normal .net property C with a getter which simply returns this.A + this.B

Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
JKC
User



Location:

Joined on:
25-Jan-2008 22:29:10
Posted:
16 posts
# Posted on: 30-Jan-2008 16:12:18.  
Otis wrote:
JKC wrote:
goose wrote:
Quote:
RIGHT... HOWEVER, what if the field that you want to modify already exists in the GENERATED Entity because it was a field in the DB... but rather than this be a standard GET, SET like the rest of the generated, you need it to be a GET only?

e.g. I dont want a NEW field, but modify one that was generated because it exists in my DB to be GET only and do the calcs.


In that case yes, when you generate the code you'll get a read only property in the corresponding generated entity.

A tip: if you need to use the calculated field value in your code after the save remember to send the refetchAfterSave parameter in the SaveEntity or SaveEntityCollection methods.


What I mean is this... I have say a TOTAL field in my DB. The Generator generates this as an INT Property with a GET, SET (we'll call it PROPERTY C). I need to modify this generated GET, SET PROPERTY C to be only GET and be the value of say PROPERTY A + PROPERTY B.

How do I do that?

UNmap the Total field in your entity in the designer: select the field then click 'remove selected field(s)', you don't need it apparently. Now, in the partial class of the entity, you add a normal .net property C with a getter which simply returns this.A + this.B



Will the .SaveEntity generated functions still work at that point for my 'new' properties? I still need the values to save to the database (and that works now as they are generated).


  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
38048 posts
# Posted on: 30-Jan-2008 17:37:29.  
Total won't have a value in the DB as it's a calculated value and has no mapped field. I also wouldn't store it as a value in the table if it's a calculated value, and thus redundant (as you can create it by adding two attributes in the same entity).

IF you have a calculated field in the database, e.g. it's calculated with a constraint of function, so it's a computed field, it's already readonly, so you don't have a setter.

If you want to make the field readonly, so no setter, you can do that in the designer: map Total again as a field and check Is readonly in the entity designer.

THough, this then assumes that Total gets its value from another source, e.g. you set it through a trigger or make it a computed column (recommended in this case).
Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
JKC
User



Location:

Joined on:
25-Jan-2008 22:29:10
Posted:
16 posts
# Posted on: 30-Jan-2008 21:00:25.  
Otis wrote:
Total won't have a value in the DB as it's a calculated value and has no mapped field. I also wouldn't store it as a value in the table if it's a calculated value, and thus redundant (as you can create it by adding two attributes in the same entity).

IF you have a calculated field in the database, e.g. it's calculated with a constraint of function, so it's a computed field, it's already readonly, so you don't have a setter.

If you want to make the field readonly, so no setter, you can do that in the designer: map Total again as a field and check Is readonly in the entity designer.

THough, this then assumes that Total gets its value from another source, e.g. you set it through a trigger or make it a computed column (recommended in this case).


Heh. Calculated columns never occurred to me.

We need the values in the DB for reporting purposes. Computed columns ought to do it however if I can figure out the logic for the computed column rating... (that is to say not in VS).

Thanks for your help. Your product seems great so far. The only thing I would say (and this may be a concept that seems good to me because I'm still new) is that it would be nice if the generated classes were regular class files that were simple to read and edit (like if we built them ourselves, with get/set options).


  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14626 posts
# Posted on: 31-Jan-2008 10:26:27.  
Quote:
The only thing I would say (and this may be a concept that seems good to me because I'm still new) is that it would be nice if the generated classes were regular class files that were simple to read and edit (like if we built them ourselves, with get/set options).

They are regular classes, but you have to account for the code re-generation process which woulod overwrite any code you have customly added, unless you add the code inside User Code Regions as described in the mentioned manual section:
LLBLGenPro Help - Using the generated code - Adding your own code to the generated classes
  Top
JKC
User



Location:

Joined on:
25-Jan-2008 22:29:10
Posted:
16 posts
# Posted on: 31-Jan-2008 14:30:38.  
Walaa wrote:
Quote:
The only thing I would say (and this may be a concept that seems good to me because I'm still new) is that it would be nice if the generated classes were regular class files that were simple to read and edit (like if we built them ourselves, with get/set options).

They are regular classes, but you have to account for the code re-generation process which woulod overwrite any code you have customly added, unless you add the code inside User Code Regions as described in the mentioned manual section:
LLBLGenPro Help - Using the generated code - Adding your own code to the generated classes


Thanks EVERYONE for your help and input. Nice personalized product support. Thanks!


  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.