How to update table without Primary key

Posts   
 
    
jab
User
Posts: 5
Joined: 06-Aug-2008
# Posted on: 06-Aug-2008 18:55:28   

I am using an older version of llblgen v 2.0.0.0 and I am trying to update a table field value using the entity that was generated. The problem I have is that I cannot update a table even though everything says it is working great. The **problem is occuring because there isn't a primary key defined **for the table I am updating. I was able to resolve a similar issue via your software by choosing the Is Part of Primary Key option available on the Mapped Entity Fields screen for the table. Unfortunately due to someone else's programming the table field that should be used as the primary key is set to except nulls.

There is a fear that changing the field to not except nulls might affect someone else's software that is using this table.

Is there some other way around my problem using llblgen? Thanks for your help.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 07-Aug-2008 05:28:42   

My first recommendation is: Try to set a PK on your DB, that would be great. Talk to your DBA, DevTeam, etc. If that isn't possible try to set the column as "NOT ALLOW NULL" then you can set the PK at the LLBLGenPro Designer.

If nothing of above is possible, the only way (AFAIK) is this (_UpdateEntitiesDirectly_):

 // (Assuming Adapter TemplateSet)
// given a fetched PersonEntity named thePerson
thePerson.Name = "name updated";
... other fields

IRelationPredicateBucket filter = new RelationPredicateBucket();
filter.PredicateExpression.Add(PersonFields.TheKey == thePerson.TheKey);

using (DataAccessAdapter adapter = new DataAccessAdapter())
{
    adapter.UpdateEntitiesDirectly(thePerson, filter);
}
David Elizondo | LLBLGen Support Team
jab
User
Posts: 5
Joined: 06-Aug-2008
# Posted on: 07-Aug-2008 19:29:50   

daelmo Thanks for responding. I seem to be stuck with the last option at the moment. And unfortunatley I am having issues with it. Can you help me with the "Assuming Adapter TemplateSet" part of your code because I can't get the adapter part of your code working.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 07-Aug-2008 20:54:58   

jab wrote:

daelmo Thanks for responding. I seem to be stuck with the last option at the moment. And unfortunatley I am having issues with it. Can you help me with the "Assuming Adapter TemplateSet" part of your code because I can't get the adapter part of your code working.

What exactly did you tried which failed (and how did it fail (exception, error, nothing happened etc.)) ? Could you post a code snippet so we know what you did so we can see where things went wrong?

Frans Bouma | Lead developer LLBLGen Pro
jab
User
Posts: 5
Joined: 06-Aug-2008
# Posted on: 07-Aug-2008 21:17:42   

Otis thanks for your help too. In a c# asp web page I have the following

EvxevticketEntity ee = new EvxevticketEntity();

   ee = em.getEvxevticketEntityFromEvxevticketid(evxevticketId);                            

     if (ee != null)
     {
                                
            ee.MedformRcvdDate = DateTime.Now;

             IRelationPredicateBucket filter = new RelationPredicateBucket();
             filter.PredicateExpression.Add(EvxevticketFields.Evxevticketid == ee.Evxevticketid);

                            
using (SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSource2 adapter = new SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSource2())
                                {
                                    adapter.UpdateEntitiesDirectly(ee, filter);
                                }

When I try to build I get an error that llblgenprodatasource2 does not contain a definition for UpdateEntitiesDirectly

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-Aug-2008 07:43:16   

This is wrong

using (SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSource2 adapter = new SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSource2())
{
     adapter.UpdateEntitiesDirectly(ee, filter);
}

You should use DataAccessAdapter object

using (DataAccessAdapter adapter = new DataAccessAdapter())
{
    adapter.UpdateEntitiesDirectly(ee, filter);
}

jab wrote:

Can you help me with the "Assuming Adapter TemplateSet" part of your code because I can't get the adapter part of your code working.

I assumed you are using Adapter not SelfServicing (ref...). Are you using Adapter or SelfServicing?

David Elizondo | LLBLGen Support Team
jab
User
Posts: 5
Joined: 06-Aug-2008
# Posted on: 08-Aug-2008 16:24:59   

Overall I haven't learned all the details about the llblgen product because I haven't been the developer that originally setup the entities and collections to interact with. Thanks for pointing me in the direction I needed to look at. We are currently using Self-servicing which is probably why I couldn't get the original code you sent working. Is there a way to do what you described using the Self-servicing option?

jab
User
Posts: 5
Joined: 06-Aug-2008
# Posted on: 08-Aug-2008 18:19:47   

Got them to change the table field to non-nullable so I got this resolved. Thanks.