Updating entity definition for exisitng entities in datastore - entity-framework

I have an app engine(Java) connected android application. I have an entity with some fields. Now I want to add another field to the entity in the new version of the app engine project. But I already have existing entities in the datastore. How can I update existing entities so that it includes the new field?

Add the new field to the model. and you will have it in the datastore, if you want to assign them values , loop through the entities and assign values and put them , other wise the datastore will return None for the records where the new field is not set

Related

Entity Framework ValueGeneratedOnAdd with no requery

Say I have EntityFramework Core 2.1.14.
Say I have to integrate data into a legacy MySql database which was created by a self-taught.
Say also that one of the tables in this database has a surrogate key field that is generated on Add.
Say then that I want to use context.SaveChanges() to handle the Insert DML generation for me because I want to be lazy and because these tables are messy.
Say finally that I do not want Entity Framework to perform a follow-up query to retrieve this surrogate field; I don't care what it is. I just need it generated on insert.
How would one call context.SaveChanges() with an Added object having a property configured as .ValueGeneratedOnAdd() but also instruct Entity Framework to do nothing but generate my INSERT ? I don't want it to return the id.

How can I delete one field of entity in Moqui?

My question is how can I delete one field of entity in Moqui which that field is deleted from database? Suppose I wrote one entity and define its field but after some time understand its false and I want delete that specific field from database how can I do this in Moqui?
Firstly, you need to delete it in your database.
Then, modify your XML entity definition.
Then, run gradlew load for reloading new database schema.

Entity Framework: auto-generate primary keys after initializing tables

I'm using Entity Framework (6) in a code-first arrangement to create a database and pre-populate it from a set of CSV files. Because the tables are coming from another application, they already have primary keys, and relationships embedded in the data make reference to those keys.
For that reason I've been using [DatabaseGenerated(DatabaseGeneratedOption.None)] when defining these tables, so that the PKs already in place get used.
However, after the data have been imported, I want to be able to add new records to the tables. How do I get the DB to assign new sequential PKs for the new records?

How to use DBContext.Add/Attach (using EF CodeFirst 4.1) with nested opbjects

Problem: When adding an object "Order" to my dbcontext, all nested objects of the order gets "readded" to the database, though the nested objects is static data and only a reference shoudl be added in the database.
Example:
The database holds 0 orders, and 3 items.
I add one order with 2 items.
Now the database hold 1 order, and 5 items. The two items in the order has been "readded" to the database, even though the items had the right primary keys before db.SaveChanges().
I realize that i may be able to attach the existing items to the dbcontext before saving changes, but is that really the only way to go? Can't EF figure out that to item already exists when the primary key matches an existing item?
Does anyone know if this is different in the new version of EF CodeFirst?
No EF cannot figure if entities are existing one or new one - both Add and Attach commands are graph oriented operations. You call them on one entity in the graph and they traverse all relations (and their relations and so on) and perform the operation for them as well.
You must figure correct state of each entity in the graph for example by using:
dbContext.Orders.Add(newOrder);
foreach(var item in newOrder.Items) {
dbContext.Entry(item).State = EntityState.Unchanged;
}
dbContext.SaveChanges();
You can use the reverse operation by calling Attach(newOrder) and set the order to Added state. The main difference will come with independent associations (for example many-to-many relations). The first approach will correctly add new relation between order and each item whereas second will not unless you manually set each relation to Added state (and changing state for relations is more complex).

LLBLGEN, how to update an existing entity

I have entity Customer under group name Customers
I moved the Customer entity to a new group TestCustomers
The Customer db table changes in the meantime renaming a field from LastName to Surname
I do a Refresh Relational Model Data from a Database in the Catalog Explorer
No changes can be seen in my TestCustomers\Customer entity as it still has a field named LastName
Is this because the Designer has some kind of binding between it and the old entity path Customers\Customer?
How can I achieve the update I want?
In LLBLGen Pro v3.5 you can try this:
In the Entity Editor, click on the Field mappings tab.
Click the Remove mapping button.
Click the Create mapping button.
Choose the correct target from the dropdown list.
This should re-create your entity including any new fields in your target db table.
There is also the Reverse-engineer unmapped target fields which can be used for this, but I found it was disabled for my entities until I remapped them. See documentation here:
http://www.llblgen.com/documentation/3.1/Designer/Functionality%20Reference/TypedViewEditor_FieldMappingsTab.htm