This will work for UD Tables , however note that you are bypassing the Epicor logic with this and using EntityFramework (the equivalent of doing an Insert directly into the Table). This is normally considered bad practice (with the Exception of UD Tables) you should use the Business Objects to do all your inserts / updates (if possible)
Here is the equivalent code using the Business Objects, you’ll have to bring in the reference to UD02 Contract in your BPM.
using(var UD02svc = Ice.Assemblies.ServiceRenderer.GetService<UD02SvcContract>(Db))
{
UD02Tableset ds = new UD02Tableset();
UD02svc.GetaNewUD02(ref ds);
ds.UD02[0].Key1 ="XX";
ds.UD02[0].Key2 = "YY";
ds.UD02[0].Key3 = "ZZ";
UD02svc.Update(ref ds);
}
Again what @danbedwards shared is perfectly valid for UD Tables, but if you want to insert / create anything else you should use the business objects.
And in your original post you mention Trigger / Stored procedure… Those should NEVER be used (specially triggers) and Stored Procedures should always be read only (if used)