Concurrency erro when deleteing or updating multiple primary key fields
The example explicitly closes the connection after the Data Access Adapter usage is finished. Fetch New Entity(new Customer Entity Factory(), order. Also the order object will be added to the Customer Entity instance 'Orders' collection. Fetching the entity using a unique constraint is done via these steps: first create an empty entity object, set the fields which form the unique constraint to the lookup value, then fetch the entity data using a special method call of the Data Access Adapter. This means that the entitys data has to be refetched from the database prior to reading from one of the entities properties.
// [C#] Data Access Adapter adapter = new Data Access Adapter(true); Order Entity order = new Order Entity(10254); adapter. Because an entity can have more than one unique constraint, you have to specify which unique constraint to use, or better: specify a filter for the unique constraint columns. Self Servicing will handle this automatically but with Adapter you must refetch manually using an adapter object.
As an example we're loading the entity identified with the customer ID "CHOPS" into an object. Contains(order) is true The logic keeps the two in sync as well.
One way to instantiate the entity in an object is by passing all primary key values to the constructor of the entity class to use: This will load the entity with the primary key value of "CHOPS" into the object named customer, directly from the persistent storage. Consider the following situation: a new Employee Entity instance employee, which has an autonumber primary key field, and a new Order Entity instance order. Employee = employee;, and the order is saved (or the employee), the field order.
In the database, several Board Member instances have been stored, as well as several different Company Car instances, of type Family Car or Sports Car. Fetch New Entity, you can load the related Company Car instance of a given Board Member's instance by using the following code: However, 'car' in the example above, can be of a different type. Option 1 is likely the most used one, since an entity might already be in memory. Because the loading of "CHOPS" already set the primary key, we can just alter a field and call Save Entity() .
If for example the Board Member instance in my Board Member has a Family Car as company car set, 'car' is of type Family Car. As with all the suggested options, the Data Access Adapter's Save Entity() method will see that the entity isn't new, and will therefore use an UPDATE query to alter the entity's data in the persistent storage. NET] Dim customer As New Customer Entity("CHOPS") Dim adapter As New Data Access Adapter(True) adapter. The Update query will solely set the table field related to the entity field "Phone".
This class is the base class for all generated entity classes and it derives from the class Entity Base2, which is located in the ORMSupport Classes assembly.
If the entity object isn't in the Context object, a new entity object is returned. Get(New Customer Entity Factory(), "CHOPS"), Customer Entity) If customer. This can be helpful if you want to refetch the entity later.
Is New Then ' not found in context, fetch from database (assumes 'adapter' is a Data Access Adapter instance) adapter. We require an adapter for this Data Access Adapter adapter = new Data Access Adapter(); adapter. If you're using a database which uses sequences, like Oracle or Firebird, be sure to define the field which should be used with a sequence as identity in the entity editor. Is New is true), Save Entity() will use an INSERT query.
An entity has a definition, the entity definition, which is formulated in a database table/view and, when you added that entity definition to your project, also has that definition in code, namely in the Entity Name Entity Base.cs/vb class.
To load the entity's data from the persistent storage, we use the generated class related to this entity's definition, create an instance of that class and order it to load the data of the particular entity via a Data Access Adapter object.In our previous example about Board Member and Company Car, Board Member is a derived type of Manager which is a derived type of Employee. An example for code using the first method: (it keeps the connection open for performance) // [C#] Customer Entity customer = new Customer Entity("CHOPS"); Data Access Adapter adapter = new Data Access Adapter(true); adapter. The following code performs the same update as the previous example code illustrating option 1.