I started to work with Serenity a couple of days ago and i got stacked by a small problem.
I have a grid made by a view of 2 Tables and i would like to add the values from that grid in those tables.
I know that i can not add from view directly and i need to create some functions which will add those items in the right place in those tables.
This is an example of the schema:
I created a view so the grid will be displayed with columns from both tables.
This is an example of the grid:
Serenity is great tool if you want to build an app very quick but is not very user friendly if you want to modify something in the code that is generated.
I tried to add some functions from StackOverflow, but that will modify the entire functionality of the program and this type of request is used only once. I can not modify the default create function, because for the rest of the tables this function will be useless.
If someone tried to work with Serenity and have an idea please give a hint so I can resolve this issue.
Thanks!
Serenity is great and I thank the guy. For those who may hit this thread don't give up. Check the current documentation. I have a few points that may be of help to those who follow. I had a proper db with foreign keys and stored procs that I wished to use to improve performance. I also had model classes mapped to the procs representing the objects I wished to use which routinely include multiple tables joined in the procs.
I found that Serenity included the joined table columns in the entity row class but not in the columns class and the row class property was attributed with the Expression tag which I removed. I believe I saw a comment from the author that he uses the foreign key declarations for this purpose.
I my case I was able to add a property to the columns class.
In the endpoint class I retrieved my proc results into my domain objects and then populated a list of the row class instances and added that list to the method return object.
This process resulted in a properly populated grid object.
Had I known how this worked to start with, it would be better to populate the list of row class objects directly.
Hope this helps.
Serenity allows updating two tables at once, there is even a sample for this in Customer dialog. At the bottom, Customer Details are listed from and updated on a separate table.
Serenity doesn't make assumptions about your UI or tables, unlike Mark Ewer states. I use Serenity on so many different legacy applications and databases, so it has to adapt to any DB structure.
Of course, because code generator handles simple cases, generating UI for a simple table is easier. For more complex cases, you should know where to inject the plug. Thats where samples, docs and GitHub issues comes in.
Related
I'm setting up a data warehouse (in SQL Server) together with our engineers we got almost everything up and running. Our main application also uses SQL Server as backend, and aims to be code first while using the entity framework. In most tables we added a column like updatedAt to allow for incremental loading to our data warehouse, but there is a many-to-many association table created by the entity framework which we cannot modify. The table consists of two GUID columns with a composite key, so they are not iterable like an incrementing integer or dates. We are now basically figuring out the options on how to enable incremental load on this table, but there is little information to be found.
After searching for a while I mostly came across posts which explained how it's not possible to manually add columns (such as updatedAt) to the association table, such as here Create code first, many to many, with additional fields in association table. Suggestions are to split out the table into two one-to-many tables. We would like to prevent this if possible.
Another potential option would be to turn on change data capture on the server, but that would potentially defeat the purpose of code first in the application.
Another thought was to add a column in the database itself, not in code, with a default value of the current datetime. But that might also be impossible / non compatible with the entity framework, as well as defeating the code first principle.
Are we missing anything? Are there other solutions for this? The ideal solution would be a code first solution, or a solution in the ETL process without affecting the base application, without changing too much. Any suggestions are appreciated.
Environment: ASP.NET MVC application with EF (Database-first with control over the db design) and Sql Server.
I have a lot of entities that have user-generated properties. I need a way for the user to be able to specify the order of these elements.
Slightly more detail: The user can create a "template" that they can then add "properties" to. These "properties" need to be ordered. There is also >= 4 other different entity types that also require user-specified ordering.
I have no problem with the front-end aspect of this, but I want to know what is the best way to persist the element order in sql server.
The obvious solution to me is to give each entity a column "Order" (or another non-keyword name) and, upon a reordering (eg. moving element #4 to #2) update all affected entities.
Is this the best way to solve this problem?
This doesn't sound like a small project and you might have various other dynamic customizations on top of the SortOrder property.
Adding an SortOrder column to your entity table is certainly not a bad approach, but this approach might clog up your data with information that doesn't necessarily belong to that entity (especially if multiple users can customize the same instances).
So I've got an alternative idea for you:
Add a CustomizationNode table (or something similar) to your database
Here you store SortOrder and potentially other kinds of metadata and user customizations which are not necessarily part of the conceptual entity.
Then, should you need to add/change/remove any customization info, you'll only need to do so in one table rather than several. And you don't need to migrate your entities whenever you change the customization capabilities.
Depending on your situation, you can link them in one of several ways:
1. Add a single column CustomizationNodeId to each entity table
This pertains to having a single customization per entity instance and is the simplest solution.
Also one customization could be shared across multiple entities of the same type (or even different types, though that probably doesn't make much sense)
2. Add multiple columns EntityXId, EntityYId to the CustomizationNode table.
In principle, only one of these ID fields would be filled and the others will be empty. Can seem a bit "off", but is not necessarily a wrong way to do it.
While you lose the ability to share a customization across multiple entities of the same type, you gain the ability to have multiple customizations per entity and additional FK's such as the UserID. This would allow you to have a per-user customization.
3. Add a link table between each EntityX and CustomizationNode
This is the most complex but also the most versatile solution. It embodies adding a table with a FK to each table you wish to link.
One important benefit you gain is additional decoupling. Customizations and entities don't know of eachother's existence and change without impacting one another.
Furthermore you can add additional metadata to those link tables, such that you can have things like versioning on top of everything mentioned above in 1 and 2.
The bottom line is, if your application is highly dynamic and customizeable then you might want to store "metadata" separately from your actual "data".
I want to create a dynamic datadriven application for practice purposes.
If I have a Modell with a Entity and I need a new one, then I want to create it only in the Diagram (modell) and thats all.
Everything else should be done dynamically, adding the new entity to b.e a Listbox, make it clickable and create a "Show Datas" and a "New/Edit" Tab with the right labels and textboxes in it. (For editing/creating new)
What I would like to know is, how can I:
Get the number of the entities
Is it possible to update the database, without needing to delete it and create new (Else I would loose all Data), if hopefully yes, how?
Get all the fields from a Entity? (Do I must work here with Reflection?)
Hope someone could help
1.Get the number of the entities
Using Context object you get the list of entities. there you can use the .Count() to check the no of entities of that type.
2.Is it possible to update the database, without needing to delete it and create new (Else I would loose all Data), if hopefully yes, how?
This question is little unclear. you want to delete database.. or entity?? you can do any operation on entities that will be reflected on back end if you want. Regarding database delete and create operation, entity framework is not designed for.
Yes you can add new entity to model and then map it with the back end tables.. it is possible to modify the model as per your backend. Even you can create you custom entites that reflect operation on multiple tables on the database but with some care about data integration.
3.Get all the fields from a Entity? (Do I must work here with Reflection?)
Yes.. To access the properties of Entity with out knowing their name you should go through reflection.
Our team is currently working on a large project which makes heavy use of foreign key tables as they are used on our TeamMember Management Webapp.
Basically, one TeamMember can be in a Team, in an Area and a TeamArea (the latter for editing and rights management).
My main goal is focused on retrieving the data for showing these FK Fields as real DropDownLists with values behind instead of TextBoxes with the FK_ID number in my edit/create view.
What I have tried so far:
Create a FormViewModel which would store all other data a lists. Conclution: Not usable as I would need to pass / create another instance of my repository.
Directly implement those lists on the TeamMember Class - but that didn't really work out well.
Also thought about harcoding it in the repository but couldn't really get the data out correctly from the tables.
What would be the best and "cleanest" approach to accomplish that?
Your first option is the best, I'm not sure why you would dismiss it so easily. What's wrong with passing or creating another instance of your repository? That shouldn't really do much more than initialize your provider.
The normal pattern is for your models to get data from a repository, so it seems to me that you should revisit this.
I am designing a dashboard to display corporate metrics (currently with ASP.net 3.5 in C#), and looking for advice on design. I'm not as used to OOP in web applications.
There may be many different metrics that can be seen by different users in a Many-to-Many relationship. I am storing the users in a local SQL database and it of course makes sense to store the metadata for each "Metric" as well. This also provides a sort of access control list for each one. Each metric can have several different charts which have different designs (bars, columns, pies, lines, or combinations of those with different series on different y-axes, etc...).
These charts could be designed programmatically and then added to the ASP.net page at runtime. It would be nice to have an inheritance structure of a superclass of a blank chart and different chart types that extend that.
The page would select the charts the given user has the right to view and then generate those. Still, I'm seeing some kind of big switch statement as a crude lookup table for the appropriate subclass to instantiate based on the information selected in the database.
Is there a more artistic way to do this? Somehow supplying the type declaration at runtime? Should I move all the style information about the charts into the database and have additional tables and columns for series, datapoints, colors, etc, where a single chart class does all the necessary queries and builds a chart? Thanks.
I realized what I'm looking for could be solved with dynamic class loading.
There's a great example of dynamic class loading in C# here from Michael Clarke.
Basically I can load a class based on a string filename coming from a query.
You could store the Strong name of the class in the DB and then simply create an instance of the class.
So instead of sorting that its a bar chart you might store something like
YourNamespace.UI.Charts.Bar
Personally I wouldn't be too scared of just storing a chart type though as it provides you with a layer of abstraction that may be helpful.