2.0 EntityCollection doesnt include column :? :?

Posts   
 
    
lyndon_h
User
Posts: 79
Joined: 14-Sep-2004
# Posted on: 20-Sep-2006 04:15:58   

I have a table that has 2 fk keys. 1 of the keys is required (A), the other is not required (B). Both keys are of the numerical db type and are mapped to the .net decimal type.

A simple FetchEntityCollection call returns a collection, but the collection does not contain the B column. I have fiddled with the "generate as nullable" checkbox in the GUI with no luck. Where is the B column in the collection?

Has anyone seen this behavior before? confused confused

FYI: Im using an Asp.net Gridview control to verify the contents of the Entitycollection. Im using the adapter method.

thanks, Lyndon

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 20-Sep-2006 05:08:09   

Can you post the code that isn't performing like you would expect and what you are expecting it to do? Sometimes that really helps to make things clear.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 20-Sep-2006 09:30:39   

Is the field available in the entity in the generated code? Could you please rebuild the solution, and eventually, close the forms, close vs.net, restart vs.net, reload the solution and open the form again?

Frans Bouma | Lead developer LLBLGen Pro
lyndon_h
User
Posts: 79
Joined: 14-Sep-2004
# Posted on: 20-Sep-2006 14:47:56   

Otis wrote:

Is the field available in the entity in the generated code? Could you please rebuild the solution, and eventually, close the forms, close vs.net, restart vs.net, reload the solution and open the form again?

I just restarted everything. I also cleaned the solution, with no luck

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Sep-2006 14:58:49   

Please follow the following steps (even if they seem "the obvious"):

1- The field exists in the Entity Property in the LLBLGen Pro Designer. 2- You don't have a source control application holding the entity file from being overwritten. 3- Re-Generate the Code. 4- Check if a property corresponding to that field does exists in the generated entity class. 5- Make sure your application references the latest generated code. 6- write 2 line of codes that created an instance of your entity and then try to access the field. 7- If no errors are found during compilation. Then everything is working as expected.

8- now we go to the grid view, check that the BoundField has the correct attribute values and that it does not have Visible="false".

lyndon_h
User
Posts: 79
Joined: 14-Sep-2004
# Posted on: 20-Sep-2006 15:01:07   

bclubb wrote:

Can you post the code that isn't performing like you would expect and what you are expecting it to do? Sometimes that really helps to make things clear.

Sure,


DataAccessAdapter da = new DataAccessAdapter();

EntityCollection atmColl = new EntityCollection(new EN_CUST_ATMEntityFactory());
da.FetchEntityCollection(atmColl, null);
GridView1.DataSource = atmColl;
GridView1.DataBind();

EN_CUST_ATMEntity atm = new EN_CUST_ATMEntity(1);
da.FetchEntity(atm);
Response.Write("atm.BRANCH_ID= " + atm.BRANCH_ID);

The table has the following columns ATM_ID ATM_NAME BANK_ID (fk #1) required SHOWING BRANCH_ID (fk #2) not required NOT SHOWING ZIPCODE ATM_DATE (autodate) not required NOT SHOWING

EntityCollections are not containing the BRANCH_ID column, but the call to the singular entity above returns the BRANCH_ID.

Oddly enough, the ATM_DATE column is not being returned in the collection either. It is also a nullable column in the designer, and not required in the db. Both the BRANCH_ID and ATM_DATE columns have the "(.NET 2.0) Generate as nullable type" checkbox checked in the designer. The BRANCH_ID column is using a different type in the designer. It is using System.Boolean (using SD.LLBLGen.Pro.TypeConverters.BooleanNumericConverter).

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Sep-2006 15:07:15   

For .NET 2.0, you should use this declaration to define a generic EntityCollection instance:

EntityCollection<EN_CUST_ATMEntity> atmColl = new EntityCollection<EN_CUST_ATMEntity>(new EN_CUST_ATMEntityFactory());
lyndon_h
User
Posts: 79
Joined: 14-Sep-2004
# Posted on: 20-Sep-2006 15:09:17   

Walaa wrote:

Please follow the following steps (even if they seem "the obvious"):

1- The field exists in the Entity Property in the LLBLGen Pro Designer. 2- You don't have a source control application holding the entity file from being overwritten. 3- Re-Generate the Code. 4- Check if a property corresponding to that field does exists in the generated entity class. 5- Make sure your application references the latest generated code. 6- write 2 line of codes that created an instance of your entity and then try to access the field. 7- If no errors are found during compilation. Then everything is working as expected.

8- now we go to the grid view, check that the BoundField has the correct attribute values and that it does not have Visible="false".

thanks for the post, I tried all of your steps, with no luck. I tried to bound the EntityCollection to a DataGrid and the same columns were output.

One thing i failed to mention is that this project was upgrated from v1.0.2004.1,v1.0.2004.2,v1.0.2005.1,v2.0

lyndon_h
User
Posts: 79
Joined: 14-Sep-2004
# Posted on: 20-Sep-2006 15:14:08   

Walaa wrote:

For .NET 2.0, you should use this declaration to define a generic EntityCollection instance:

EntityCollection<EN_CUST_ATMEntity> atmColl = new EntityCollection<EN_CUST_ATMEntity>(new EN_CUST_ATMEntityFactory());

Walaa, Using the code above gives the same results. I'm using the SD.TemplateBindings.SharedTemplates.BackwardsCompatibility.NET20 template binding.

thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 20-Sep-2006 16:37:33   

PLease check: - is the field available in the entity in the DESIGNER? - is the field as property available in the entity CLASS in the generated code?

Frans Bouma | Lead developer LLBLGen Pro
lyndon_h
User
Posts: 79
Joined: 14-Sep-2004
# Posted on: 20-Sep-2006 16:57:42   

Otis wrote:

PLease check: - is the field available in the entity in the DESIGNER? - is the field as property available in the entity CLASS in the generated code?

Yes, the field is available in the designer. The designer displays the field as a nullable type with the "(.NET 2.0) Generate as Nullable" type checkbox checked.

The entityClass does have the the BRANCH_ID property available. I can call an instance of the class and output the value. However, the column is not available in EntityCollections. The code i am using is below. The collection lists the correct number of rows, but nullable columns are missing. The code which outputs the BRANCH_ID of a singular entity (in the response.write call below) displays the value.


                 DataAccessAdapter da = new DataAccessAdapter();

                 EntityCollection<EN_CUST_ATMEntity> atmColl = new EntityCollection<EN_CUST_ATMEntity>(new EN_CUST_ATMEntityFactory());
                da.FetchEntityCollection(atmColl, null);

                GridView1.DataSource = atmColl;
                GridView1.DataBind();

                EN_CUST_ATMEntity atm = new EN_CUST_ATMEntity(1);
                da.FetchEntity(atm);
                Response.Write("atm.BRANCH_ID= " + atm.BRANCH_ID);


the property definition in the EntityClass is below:


        /// <summary> The BRANCH_ID property of the Entity EN_CUST_ATM<br/><br/>
        /// </summary>
        /// <remarks>Mapped on  table field: "EN_CUST_ATM"."BRANCH_ID"<br/>
        /// Table field type characteristics (type, precision, scale, length): Decimal, 18, 0, 0<br/>
        /// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
        public virtual Nullable<System.Decimal> BRANCH_ID
        {
            get
            {
                object valueToReturn = base.GetCurrentFieldValue((int)EN_CUST_ATMFieldIndex.BRANCH_ID);

                return (Nullable<System.Decimal>)valueToReturn;
            }
            set { SetNewFieldValue((int)EN_CUST_ATMFieldIndex.BRANCH_ID, value); }
        }

I hope this helps

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 20-Sep-2006 17:02:36   

Ok, the field is there, so it's not viewed in the grid. Could you in the grid set the datasource to nothing and then back to the llblgenpro datasource? Or if you don't want to do that, open the column editor of the grid and check if the column is available to you?

Frans Bouma | Lead developer LLBLGen Pro
lyndon_h
User
Posts: 79
Joined: 14-Sep-2004
# Posted on: 20-Sep-2006 17:14:53   

Otis wrote:

Ok, the field is there, so it's not viewed in the grid. Could you in the grid set the datasource to nothing and then back to the llblgenpro datasource? Or if you don't want to do that, open the column editor of the grid and check if the column is available to you?

Fran, I really appreciate the quick responses.

I set the datasource to null, the recompiled and ran the code. I then set it back to the entityCollection. Same response.

I have tested this EntityCollection with 3 different grid types (.NET GridView, .NET DataGrid, DevExpress AspxGrid). Im autobinding all of the grids and non of the column definitions are available through visual studio's designer. The code im using for grids is:


 <asp:GridView ID="GridView1" runat="server" CellPadding="4" GridLines="None">
        </asp:GridView>
        
        <asp:DataGrid ID="DG1" runat=server></asp:DataGrid>

then i'm loading the grids with the whole entityCollection. I'm not binding any columns, so the whole entityCollection should be available.

lyndon_h
User
Posts: 79
Joined: 14-Sep-2004
# Posted on: 20-Sep-2006 17:56:54   

FYI: I changed the definition of the column in the database to not allow nulls and regenerated the code. The column now shows in my Asp.net grids....

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 20-Sep-2006 17:57:32   

WHen you open the designer of the LLBLGenProDatasourcecontrol, is the dropdownlist for the factories empty or can you select a factory?

Could you try setting it up in design time view? You haven't specified that you want the grid to auto-gen the columns in your html.

Frans Bouma | Lead developer LLBLGen Pro
lyndon_h
User
Posts: 79
Joined: 14-Sep-2004
# Posted on: 20-Sep-2006 18:22:44   

Otis wrote:

WHen you open the designer of the LLBLGenProDatasourcecontrol, is the dropdownlist for the factories empty or can you select a factory?

Could you try setting it up in design time view? You haven't specified that you want the grid to auto-gen the columns in your html.

I set a LLBLGenDS2 up with the ATMEntityFactory as my source. I hooked it up to my grid and the BRANCH_ID didn't show. So I looked at the columns collection of the GridView in VSnet and found the BRANCH_ID! I had to manually include it (even though AutoGenerate fields is set to True), and now the Grid displays the column. So I've figured out how to make it work, but i dont understand why. Shouldnt AutoGenerate generate all columns?

lyndon_h
User
Posts: 79
Joined: 14-Sep-2004
# Posted on: 20-Sep-2006 18:34:52   

OK. I deleted the Grid and added a new one with the LLBLGenDS2 as the datasource and the BRANCH_ID was there automatically. But it doesnt work that way with the code behind call. I cant get the BRANCH_ID column to be populated using the codebehind method of adding an entityCollection. I have lots of legacy code that i'm trying to recompile and test, so redoing everything using LLBLGenDS2s is not permissible. Any ideas why this might be happening?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 20-Sep-2006 19:02:09   

AutoGenerate should indeed show all columns, so it's indeed odd that it doesn't work, or better: that it doesn't show that column... I've a testproject for this kind of things, I'll see if I can repro it like this.

(edit). I can't repro this:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default12.aspx.cs" Inherits="Default12" %>

<%@ Register Assembly="SD.LLBLGen.Pro.ORMSupportClasses" Namespace="SD.LLBLGen.Pro.ORMSupportClasses" TagPrefix="llblgenpro" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <llblgenpro:LLBLGenProDataSource2 ID="LLBLGenProDataSource2_1" runat="server" AdapterTypeName="NWTest.DatabaseSpecific.DataAccessAdapter, NWTestDBSpecific" DataContainerType="EntityCollection" EntityFactoryTypeName="NWTest.FactoryClasses.CustomersEntityFactory, NWTest">
        </llblgenpro:LLBLGenProDataSource2>
        <asp:GridView ID="GridView1" runat="server" DataKeyNames="CustomerId" DataSourceID="LLBLGenProDataSource2_1">
        </asp:GridView>
    
    </div>
    </form>
</body>
</html>

Shows all the columns fine at runtime.

Frans Bouma | Lead developer LLBLGen Pro
lyndon_h
User
Posts: 79
Joined: 14-Sep-2004
# Posted on: 20-Sep-2006 20:01:36   

Otis wrote:

AutoGenerate should indeed show all columns, so it's indeed odd that it doesn't work, or better: that it doesn't show that column... I've a testproject for this kind of things, I'll see if I can repro it like this.

(edit). I can't repro this:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default12.aspx.cs" Inherits="Default12" %>

<%@ Register Assembly="SD.LLBLGen.Pro.ORMSupportClasses" Namespace="SD.LLBLGen.Pro.ORMSupportClasses" TagPrefix="llblgenpro" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <llblgenpro:LLBLGenProDataSource2 ID="LLBLGenProDataSource2_1" runat="server" AdapterTypeName="NWTest.DatabaseSpecific.DataAccessAdapter, NWTestDBSpecific" DataContainerType="EntityCollection" EntityFactoryTypeName="NWTest.FactoryClasses.CustomersEntityFactory, NWTest">
        </llblgenpro:LLBLGenProDataSource2>
        <asp:GridView ID="GridView1" runat="server" DataKeyNames="CustomerId" DataSourceID="LLBLGenProDataSource2_1">
        </asp:GridView>
    
    </div>
    </form>
</body>
</html>

Shows all the columns fine at runtime.

I stepped through the .NET debugger and looked at the contents of the EntityCollection. it seems as if though columns with a type of "type?" are being dropped from grids when directly binding to the grids. Apparently there is mapping code within the LLBLgenDS2 that maps the "type?" to the appropriate .NET type. This is apparently why i cant bind to grids unless i bind through the LLBLGenDS2 object. I took a look at the documentation labeled "Migrating your code" where you wrote about changing the value of GenerateNullableFieldsAsNullableTypes to false. I did that, but it doesnt solve the problem.

The field definition is still nullable (see code below)


public virtual Nullable<System.Decimal> BRANCH_ID
        {
            get
            {
                object valueToReturn = base.GetCurrentFieldValue((int)EN_CUST_ATMFieldIndex.BRANCH_ID);

                return (Nullable<System.Decimal>)valueToReturn;
            }
            set { SetNewFieldValue((int)EN_CUST_ATMFieldIndex.BRANCH_ID, value); }
        }

The GenerateNullableFieldsAsNullableTypes = False (in the propertys tab of the designer) is not changing the field from a Nullable<System.Decimal> to a System.Decimal type.

FYI. Im making sure that my generated code is overwriting the old Entity definition file.

edit: The generated code is overwriting the old Entity file

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 20-Sep-2006 21:01:32   

Please use the plugin to set/reset the nullable flags. You can use that plugin (its available to you by rightclicking an entity or 'Entities') the setting you're setting is for NEW entities. The plugin is added alter to bulkset the flag.

You might be right about the nullable properties. I tested it with customers, which has only strings.

So I tested it with Employees instead... BINGO. It doesn't show fields of type Nullable<T>. Big bug in the gridview, but there are more bugs when it comes to nullable types and databinding (in Microsoft's code that is), so IF possible you can do two things: - setup the grids at design time, and use nullable types OR - with the plugin, switch off nullable types on all fields and use autogenerate fields.

Frans Bouma | Lead developer LLBLGen Pro
lyndon_h
User
Posts: 79
Joined: 14-Sep-2004
# Posted on: 20-Sep-2006 23:34:40   

Otis wrote:

Please use the plugin to set/reset the nullable flags. You can use that plugin (its available to you by rightclicking an entity or 'Entities') the setting you're setting is for NEW entities. The plugin is added alter to bulkset the flag.

You might be right about the nullable properties. I tested it with customers, which has only strings.

So I tested it with Employees instead... BINGO. It doesn't show fields of type Nullable<T>. Big bug in the gridview, but there are more bugs when it comes to nullable types and databinding (in Microsoft's code that is), so IF possible you can do two things: - setup the grids at design time, and use nullable types OR - with the plugin, switch off nullable types on all fields and use autogenerate fields.

thanks for all your help, Fran. It looks like M$ is having a time with Nullable fields and grids. im trying to run the plugin to reset nullable flags, but i dont see it. I only see 4 plugins in my designer -toggle hide/flags of M:N... -add/remove additional interface/namespace -assign type converters (I took a look at this one, but i didnt see anything) -add custom properties plugins

do i need to load another plugin to reset nullable flags?

thanks

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Sep-2006 09:32:26   

I have 6 plugins.

What's the release date of your designer (Help -> about)?

lyndon_h
User
Posts: 79
Joined: 14-Sep-2004
# Posted on: 21-Sep-2006 22:40:19   

Walaa wrote:

I have 6 plugins.

What's the release date of your designer (Help -> about)?

August 3rd, but the runtime libs,task, templates, and drivers were updated with the Sept 20 build. I'll download the full version and run it.

lyndon_h
User
Posts: 79
Joined: 14-Sep-2004
# Posted on: 21-Sep-2006 22:44:26   

lyndon_h wrote:

Walaa wrote:

I have 6 plugins.

What's the release date of your designer (Help -> about)?

August 3rd, but the runtime libs,task, templates, and drivers were updated with the Sept 20 build. I'll download the full version and run it.

Better yet, i'll download the designer runtimes and see if that gives me access to the 6 plugins simple_smile

lyndon_h
User
Posts: 79
Joined: 14-Sep-2004
# Posted on: 22-Sep-2006 18:04:46   

that did it. Thanks for all the help, Fran and Walaa