I'm new to Entity Framework and am using Database First. I have inherited a project where I am making changes. I have a table called Bid to which I've added column Auciton_Status_Id. I then updated the .edmx file (whatever that is for) by opening it up and selecting Update Model from Database. I had a .tt file (whatever that is for) in another project which I had to manually update by right clicking on it selecting Run Custom Tool. Problem is that the .tt file in the same project as the .edmx file has an associated .cs file (with a class with signature public partial class Entities : DbContext) (whatever a DBContext is) and it has a method called
public virtual int MakeBid(Nullable<long> lotId,
Nullable<decimal> bidValue,
Nullable<System.DateTime> createdDate,
Nullable<long> bidStatusId,
Nullable<System.Guid> userId)
Problem is I want my new column Auction_Status_Id to be added to this method as well. How do I do that when this is an autogenerated class?
MakeBid is probably a stored procedure, so if you modify it in de database you can refresh the .edmx again.
(and make sure you know what it is for :D).
Related
Similar post to this:
Curious about properly defining the DAC.
I have a T-SQL CREATE VIEW script that I've added to the 'Database Scripts' are of the Customization project as shown. But I suspect that I haven't added the DAC properly. When I attempt to add this DAC within the context of a Generic Inquiry 'Add Related table' screen I do not get any results when searching for the name of the DAC I tried to create.
When I initially attempted to define the DAC in the 'Code' area, the system complained that the object didn't exist in the database. This makes sense as it's a SaaS instance and I've just created the T-SQL view from a local copy of the database.
So I just added the CREATE VIEW statement within the 'Database Scripts' area and published the customization successfully.(This implies to me that the object exists in the database now).
But I now believe I need to retroactively 'Generate Members from Database' in order to identify the key fields so Acumatica can see how it aligns with other DACs. Is this a correct assumption?
In the CODE area I see this (where vGFCINItemClassSeg is the name of the SQL view )
using System;
using PX.Data;
namespace vGFCINItemClassSeg
{
[Serializable]
[PXCacheName("vGFCINItemClassSeg")]
public class vGFCINItemClassSeg : IBqlTable
{
}
}
Any suggestions on how to properly provide Acumatica with what it needs to associate this to the INItemClass table in the database and make it available as a DAC?
Got this resolved.
Problem was that I had attempted to add the DAC prior to adding the Database script.
Solution: unpublish the customization package. drop the custom SQL view from the database. Start a new customization package. Add the Database Script first. THEN publish. Then after that is successful, re-open the customization project and add the DAC as a second step.
I would like to make a Plugin where the user can select a source and then a target element and get all the parameters and their values.
My problem is: After I selected the source element and got all parameters and values into comboboxes I select the target (via another button). For that the form closes again and after selecting and reopening all the data from the source element is gone.
What would be a correct way to do this?
At this time both buttons close the form run another ExternalEvent to select the element and collect the data.
Can I cache this data (Lists, dictionary with list, dictionary with dictionary with list) or do I have to write it to a file or is there another way?
How do I keep/remember the data I collected when a form closes an reopens?
Thank you for any help
Philipp
There multiple ways of doing this I guess. It is more of a general programming rather than API issue. You basically need to keep the data in memory outside of just the WPF window.
Some options of the top of my head would be
Save the data into file in temp folder and read it when needed (probably a messy solution)
Create & instantiate a class with data to keep in memory and communicate it between different windows etc.
Have a Static Class with appropriate property. Once selecting an element assign it to the property. This should persist within the Revit session. Static Class.
Option 3 should be the easiest to use.
Just use Properties -> Application settings to store the ID of the entity. Then on launch get the combo boxes to auto populate if the ID can be found.
External events are only required when editing the model.
This is assuming your using Visual studio and not sharp develop. If your still using sharp develop it is time to move on to a real IDE.
I think there are a few options. You could use the built in DataStorage that a revit model provides. Here, i made a datastorage entity to store a GUID for a project...
public Guid schemaGuid = new Guid("{5F374308-9C59-42AE-ACC3-A77EF45EC146}");
public DataStorage dataStorage;
public string schemaName = "UniqueProjectId";
public DataStorage dataStorage;
public string SimpleField = "MyProjects_GUID";
public Schema CreateNewDataStorage()
{
Guid newProjectGuid = Guid.NewGuid();
Transaction t = new Transaction(doc, "Make internal storage");
t.Start();
dataStorage = DataStorage.Create(doc);
dataStorage.Name = schemaName;
SchemaBuilder schemaBuilder = new SchemaBuilder(schemaGuid);
schemaBuilder.SetSchemaName(schemaName);
schemaBuilder.AddSimpleField(SimpleField, typeof(Guid));
schema = schemaBuilder.Finish();
entity = new Entity(schema);
entity.Set(SimpleField, newProjectGuid);
dataStorage.SetEntity(entity);
t.Commit();
return schema;
}
Another way would be to write to external database or text file. For something small, SQlite is easy. A temporary text file is also a very simple way to temporarily store data.
Lastly, you could use an Idling event and keep the dialogue box active.
I need to perform soft deletion using jhipster.
Ex:
If user click on delete button I need to mark is_active flag to false.
Writing custom code will be the only solution or is there any way to do it?
Things I have done so far :
I have followed Jhipster web site and created Monolithic application.
Then I have created new entity called 'Student' using the entity sub-generator . (filed names : id, name age, address and is_active. )
The Sub generator generated files contain all the basic CRUD operations and provided a CRUD front-end for student entity.
The front end contains buttons for create student, view, edit and delete.
When I Click on a delete button the studuent record will be permanatly delete from the database.
But my Requirement is to keep the record in the database and mark only the is_active filed in to false.
Basically I need to keep history data of the student without permanatly deleting them.
you will have to edit it yourself. First of all, I recommend you to extend all classes generated by JHipster (except for Resources, you will have to create another class and use a custom mapping thus changing the service in the frontend)
Extend your StudentRepository and create a method that updates the is_active value (it would be better if it receives the id and the value: true or false)
Extend yout StudentService and create a new method (e.g. call it public void disableAddress(Long id))
In that method the your newly created method in the repository layer
Edit StudentResource and change the code inside the deleteStudent method and call your newly created method in the service layer
If you created a new resource, change the service calling your api.
Hopefully it is not a stupid question - can I use BQL to query a new field that I just added through customization in database?
I just added a new field to "contract" table through "System->Customization" - I created a project there and added a new field called "ProductCode" (it automatically became "UsrProductCode" in database), and the field does show in "contract" table as well as the "contract template" screen (CT202000) after successful compilation and publish, exactly as I expected, however, I got error:
The type name 'UsrProductCode' does not exist in the type 'PX.Objects.CT.Contract' in file: Code#SOOrderEntry(80)
when I then tried to use this field in a BQL as below:
// Lookup contract template ID
Contract template = PXSelect<Contract,
Where<Contract.isTemplate, Equal<boolTrue>, And<Contract.UsrProductCode, Equal<Required<Contract.UsrProductCode>>>>>
.Select(Base, inventoryCD);
I thought adding new field through customization would automatically make it available for BQL query but it seems I was wrong - what would I need to do in order to make it be able to be used in BQL?
Thanks for your help.
Edited:
Following suggestion from #Jeff Williams, I tried to find out the class definition file related to my customization - the only file I found is "PX_Objects_CT_Contract_extensions.cs", which is under "C:\Program Files (x86)\Acumatica ERP\AcumaticaERP\App_Code\Caches" and the code is very simple as below:
public class PX_Objects_CT_Contract_Extension_AddColumn: PXCacheExtension<PX.Objects.CT.Contract>{
#region UsrProductCode
[PXDBString(30)]
[PXUIField(DisplayName="Product Code")]
public virtual string UsrProductCode{get;set;}
public abstract class usrProductCode : IBqlField{}
#endregion
I also tried to use "PX_Objects_CT_Contract_Extension_AddColumn.UsrProductCode" in BQL and got error during compilation:
'PX_Objects_CT_Contract_Extension_AddColumn.UsrProductCode' is a 'property' but is used like a 'type' in file:
Can somebody tell me what else I need to do to make this new field available for BQL?
It does add it however you cannot reference it as "Contract.Usr..." it would be under something like "ContractExtension.Usr...".
Look at the data class where the DAC extension is and see what that name is. If your BQL is in a different name space you will need to add a reference to the codeclass namespace as well.
I have created a DataBase in SQL and created an EDMX in Visual Studio 2012. It automatically created POCO (TT) classes. Everything looks fine.
Now I change the column name of a table. I update the EDMX. Opening the EDMX in XML and everything looks fine.
Question 1
After I ran Custom tool in TT, I see that a new property got created additionally, e.g.:
SQL table name : Student
Column name : sName
In my POCO Class
public int sName{ get; set; }
got automatically created.
Now I change the column name in SQL to
Column name : studentName
My POCO class
public int sName{ get; set; }
public int studentName{ get; set; }
Is this a bug or do I need to do something to fix this?
What should I do to avoid this?
Question 2
Also, if I change the data type of any SQL column and update the model from the DB in my EDMX designer, the Conceptual Model is not updated. How do I go about this?
First, to understand your problem, what you need to know is that the EDMX file is just an XML file that contains 3 different sections:
CSDL: Conceptual schema definition language
SSDL: Store schema definition language
MSL: Mapping specification language
The CSDL contains the entities and relationships that make up your conceptual model. The SSDL describes your DB model and the MSL is the mapping between the 2.
The “Update Model From DB” process will update the SSDL (change everything that is inconsistent with the current DB schema), it will only modify the CSDL in case you’ve added new things to your DB schema.
This is quite a normal behavior since your Conceptual schema may/should differ from your DB schema (unless you want your Domain model to look exactly like a DB model which obviously do not sound as OOP/DDD best practices).
As for #Peru, the solution would be to delete the concerned entity (not the entire EDMX!) and then perform the “Update Model From DB” process.
Hope this helps!
Edit:
There's a tool, not for free, which is a Visual Studio plugin that allows you apply changes made into the DB, both on the CSDL and SSDL files: Huagati DBML/EDMX Tools.
The only "free" solution is deleting the entity (or the right field within this entity) that needs to be updated.
Remember that CSDL is supposed to be maintained by developers and must look like an Object Model rather than a DB Model. Imagine you have setup inheritance between your entities or that you have split 1 DB table to 2 EDMX entities, running "Update model from DB" should not overwrite everything!
Personally, I'd open the edmx file as XML and find the problem node and delete it. The file is pretty easy to understand - don't be scared to at least try it out.
I know I'm a bit late here but there is a relatively simple way to generate your POCOs/update your DbContext from the EDMX designer.
Go to your designer, right click on the empty area, click "Update Model from Database", add/update your tables. This will update your edmx XML. After you've verified that your table has been added to the CSDL, SSDL, and MSL sections, right click on your T4 template in the solution explorer (<Name>.tt, not <Name>.Context.tt) and click "Run Custom Tool" - this will generate POCOs for any updated objects. Note that if you are creating new entities, they will not be added to your DbContext class, you will still have to do this manually by adding the following line at the bottom of your class: public virtual DbSet<Entity_Name_Goes_Here> EntityNames { get; set; }
Only the manual edit worked for a View in my project. (going from smallint to decimal(18,2) )
Open the .EDMX file in a text editor, find appropite section, and manually change the Property Type="..." value.
Once you update the fields in Db, Find the respective model.cs file then delete those fields from the model. now Update the EDMX file (Update Model from Database). It worked for me.