CodeSmith Community
Your Code. Your Way. Faster!

Compile Error on Generated Code!

Latest post 11-20-2007 11:07 AM by evolved. 14 replies.
  • 02-02-2007 2:33 PM

    Compile Error on Generated Code!

    I just downloaded the Trial version of Codesmith 4.0 and installed it. I opened up Codesmith and selected the .netTiers templates. I selected a good number of my tables, and set properties for Codesmith to generate a web-site, web-services, etc.  Opened the solution generated in Visual Studio 2005, and built the solution.

    I am getting compile errors (I haven't changed any code).

    The error message is:

    Error 1 The name 'StudentIDSource' does not exist in the current context InsideTrack.RightTrack.Domain C:\Projects\InsideTrack\ProductEval\CodeSmith\InsideTrack.RightTrack.Domain\StudentBase.generated.cs 126 5

    The generated code in the source file is:

    #region Entity Properties

     

    /// <summary>

    /// Gets or Sets the StudentID property.

    ///

    /// </summary>

    /// <value>This type is int</value>

    [Entities.Bindable,

    DataObjectField(true, false, false)]

    public override System.Int32 StudentID

    {

    get

    {

    return base.StudentID;

    }

    set

    {

    if (base.StudentID == value)

    return;

     

    base.StudentID = value;

    StudentIDSource = null;

    }

    }

    The table definition for the TermStatusTable is attached as a .png image.

     Can someone tell me what is going wrong?  Why is StudentIdSource being generated somewhere?


     


    Steven Archibald President, Steven Archibald Consulting Corporation "Real Business" Solutions The highest complement you can give me is a referral to your friends and associates.
    Filed under: , ,
    • Post Points: 65
  • 02-03-2007 11:07 PM In reply to

    • velum
    • Top 25 Contributor
    • Joined on 07-14-2006
    • Montréal, Qc, Canada
    • Posts 189
    • Points 4,731

    Re: Compile Error on Generated Code!

    Hi Steven!

    I'm not an expert and I don't know what is going on with the code you generated, but I can tell you this: StudentIdSource should be of type Student. Properties ending in 'Source' are objects referred to by the variable with the same name without the 'Source' ending. For example, an object contains an xyzSource property, it means that xyz is an FK and xyzSource is the object which xyz is pointing to. However, StudentIdSource will be loaded only if you do a DeepLoad of the parent object. In your example, TermStatus.Get(termStatus_id) would simply load the TermStatus object with ID termStatus_id and StudentIDSource would remain null. However, if you the perform a DeepLoad(...) on your object, StudentIDSource will be fetched.

    So this only tells you what StudentIDSource is, but it does not solve your problem. I'v been using .netTiers for a few months now, and I never had trouble compiling the generated code. Maybe you should try getting the latest .netTiers templates via Subversion. You will fin how here: http://www.nettiers.com/Download.aspx

    Cheers!

    JF


     

    • Post Points: 5
  • 02-04-2007 4:06 AM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 925
    • Points 34,785

    Re: Compile Error on Generated Code!

    Steve,

    Did you select the "Student" table for generation? When generating its best to select all dependant tables so you get a complete model.

    hth

    swin

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 35
  • 02-05-2007 12:11 AM In reply to

    Re: Compile Error on Generated Code!

    Swin,

    Yes, the Student table is selected for generation.

    Steven Archibald President, Steven Archibald Consulting Corporation "Real Business" Solutions The highest complement you can give me is a referral to your friends and associates.
    • Post Points: 35
  • 02-05-2007 3:24 AM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 925
    • Points 34,785

    Re: Compile Error on Generated Code!

    I think from your namespace name you're using the Domain component layer which unfortunately i haven't tried yet.  However i generated a domain layer for the Northwind db using the latest SVN templates and it seemed to gen and compile ok - although I did notice it generated some superflous code (the "xxIDSource = null" line is repeated twice in the xxID setter).

    What version of the templates are you using?

    Have you tried to generate using the Northwind db? It's probably worth it to see if its a template or db issue? 

    In the domain model the xxIDSource property should be in the same class (in the "Composite Properties" region) as the xxID property and should look something like this...

    /// <summary>
            /// Gets or sets the source <see cref="Products"/>.
            /// </summary>
            /// <value>The source Products for ProductID.</value>
            [XmlIgnore()]
            [System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)]
            public new virtual Products ProductIDSource
              {
                get {
                        if (base.ProductIDSource == null)
                        {
                            base.ProductIDSource= DataRepository.ProductsProvider.GetByProductID(this.ProductID);
                        }
                        return base.ProductIDSource as Products;
                    }
                set { base.ProductIDSource = value; }
              }

     

    hth

    swin 

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 60
  • 02-05-2007 2:03 PM In reply to

    Re: Compile Error on Generated Code!

    Swin,

    It does indeed seem to be a Domain Model issue. I downloaded the latest templates, and tried several different generation options (webservice yes & no, website yes & no, etc.). The determining factor is whether I chose the domain model in the component layer: domain model yes => compile fails. Any other choice => compile succeeds.

    I'll try with the Northwind just for completeness -- but since our corporate standard is the Domain Model, this is obviously  a deal breaker (I'm evaluating Codesmith and LLBLGen Pro) if it can't be fixed.

    Steven Archibald President, Steven Archibald Consulting Corporation "Real Business" Solutions The highest complement you can give me is a referral to your friends and associates.
    • Post Points: 5
  • 02-05-2007 3:18 PM In reply to

    Re: Compile Error on Generated Code!

    Swin,

    I have tried the Domain Model with the Northwind database. If I don't choose the option to generate a webservice, it builds cleanly. So, now the question is, how do I figure out why  source generated from my database will not compile?

    Steven Archibald President, Steven Archibald Consulting Corporation "Real Business" Solutions The highest complement you can give me is a referral to your friends and associates.
    • Post Points: 65
  • 02-05-2007 3:31 PM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 925
    • Points 34,785

    Re: Compile Error on Generated Code!

    Good question!

    In your first post you said "I selected a good number of my tables" - have you tried regening the whole of your db?

    In my previous post I listed some code from an example xxIDSource - did you get anything like this when gening against your db?

    Have you checked the FK relationship to make sure all is well?

    hth

    swin

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 5
  • 02-05-2007 3:37 PM In reply to

    • velum
    • Top 25 Contributor
    • Joined on 07-14-2006
    • Montréal, Qc, Canada
    • Posts 189
    • Points 4,731

    Re: Compile Error on Generated Code!

    Hi Steven!

    I'm wondering whether the fact that your primary key is the combination of two foreign keys matters here. I understand that it should not, since what you are doing is valid. However, following the recommendations of a DBA I know, I always have a separate primary key. (And I am using xyzSource objects and it is working). In other words, in your case, I would have created the table you are showing as follows:

    StudentStatus (StudentStatusID PK, TermID FK, StudentID FK, ...)

    And I would set a Unique Key constraint on (TermID, StudentID)

    I don't know if it would be feasible for you to modify your StudentStatus table so that it looks like the above, but I would try that.

    Cheers!

    JF

     


     

    • Post Points: 35
  • 02-05-2007 4:00 PM In reply to

    Re: Compile Error on Generated Code!

    I've done a little more research, and now have some more info.

    If table A has two columns that are together are a foreign key to the composite primary key of table B, then the correct "source" is not generated for the entity for A.  Each property for the two columns in the A entity references a <col>Source field, but neither of the two fields is sufficient information to find the source. 

    Steven Archibald President, Steven Archibald Consulting Corporation "Real Business" Solutions The highest complement you can give me is a referral to your friends and associates.
    • Post Points: 5
  • 02-05-2007 4:05 PM In reply to

    Re: Compile Error on Generated Code!

    Sorry JF,

    Didn't see your post before I posted the results of my investigation. It appears I found the same thing as you.

    The problem, of course, is the database definition is pretty much fixed. Changing the table definitions now will be a problem, as the base product is in production.  It appears netTiers is based on ALWAYS having a surrogate primary key for your tables. Not good ....

    Or maybe it's just a bug, and it'll be fixed in the next 10 minutes....

    Steven Archibald President, Steven Archibald Consulting Corporation "Real Business" Solutions The highest complement you can give me is a referral to your friends and associates.
    • Post Points: 35
  • 02-13-2007 11:31 AM In reply to

    • bosefus
    • Not Ranked
    • Joined on 02-13-2007
    • Posts 2
    • Points 70

    Re: Compile Error on Generated Code!

    I am running into this same issue. Is there a fix planned for this? Thanks.

    Eric

    • Post Points: 35
  • 02-19-2007 4:15 PM In reply to

    • ryankevin
    • Not Ranked
    • Joined on 02-19-2007
    • Posts 1
    • Points 35

    Re: Compile Error on Generated Code!

    I'm running into this problem as well...

    • Post Points: 35
  • 11-19-2007 8:24 AM In reply to

    • DanZka
    • Not Ranked
    • Joined on 11-19-2007
    • Posts 2
    • Points 40

    Re: Compile Error on Generated Code!

     Does anyone have a solution for this????

    Please post it if you have. 

    Filed under:
    • Post Points: 35
  • 11-20-2007 11:07 AM In reply to

    • evolved
    • Top 50 Contributor
    • Joined on 12-27-2004
    • South River, NJ
    • Posts 96
    • Points 1,840

    Re: Compile Error on Generated Code!

     I can take a look at it, this still only appears in the Domain model?

    Anyone have some quick DDL to create the table schema to illustrate the problem?

    http://www.jheidt.com
    ------------------------------
    Member of the .NetTiers team
    http://www.nettiers.com
    ------------------------------

    • Post Points: 5
Page 1 of 1 (15 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems