Update an entity using Unique Constraint

Posts   
 
    
Posts: 1268
Joined: 10-Mar-2006
# Posted on: 17-Jul-2006 20:00:50   

I want to update an Entity using values from the unique constraint. I know those values in code when I want to update, but do not have the the primary key.

I could of course do:

MyEntity entity = new MyEntity();
entity.FetchUsingUCBlah(12,12,115);
entity.SomeField=12;
entity.Save();

However, I dont want to have to fetch it, just to update a field when I have the values for the UC. This may already work, but the documentation does not mention it and this thread I found seems to indicate it does not.

http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=4708&HighLight=1

Any help here?

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 18-Jul-2006 02:04:38   

If your sure of the unique constraint then you can directly update rows in the database using a filter. So if your filter defines the Unique Constraint then you would only update that row with the new value. Here's an example from the manual.

// C#
OrderEntity newValues = new OrderEntity();
newValues.EmployeeID = 5;
OrderCollection updater = new OrderCollection();
updated.UpdateMulti(newValues, (OrderFields.EmployeeID == 2));
Posts: 1268
Joined: 10-Mar-2006
# Posted on: 18-Jul-2006 06:56:36   

Ok. I will put that in.

Question - Shouldn't we be able to save with UC values just like with PKey values (in theory)?

SomeEntity entity = new SomeEntity();
entity.PartOfUC1 = 1;
entity.PartOfUC2 = 2;
entity.IsNew = false;
entity.SomeValueToChange = 55;
entity.Save();

Seems like that would be a good feature - I would not have to know which way to code it, just fill out any UC values or PKey values and it work.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 18-Jul-2006 09:38:55   

UC's are defined in the generated code, not in the meta-data of the entity. This means that saving using a UC requires you to specify an update restriction filter.

Frans Bouma | Lead developer LLBLGen Pro