I'm trying to implement Audit.Net with Entity Framework, I need to create an audit table for each of my current tables and add some fields. Do I have to create all the audit entities like my actual ones and add a Migration to create it all in database? Doesn't it have some dynamic way to do it?
The library Audit.EntityFramework does not provide any dynamic way to generate migrations for audit tables. If you have any idea on how to provide this, feel free to open a new issue and add your suggestions.
Related
We are in situation to create the separate API in Python FastApi for one functionality. Other functionality in Laravel. The application which exists already. It created set of tables and using them. Now, we are required to create Pydantic schemas for new API. That schema has a relationship with existing tables. We don't want to create separate schemas for existing tables.
We are forced to create schemas for existing tables as well in the new API. We don't want to create the separate schemas and models for existing tables.
Kindly suggest
Thanks in advance
If you don't care about automatic documentation you don't need to use pydantic at all - you can just return dict and use swagger. If you do, I have no good news.
As far as I know it's not easily achievable. Even if you have tables definitions implemented in sqlalchemy there is not easy way of creating schema from them (there is a tool but it's still experimental).
There are ORM's that can do that (like tortoise) but you still need to implement schema somewhere. Dynamic creation of python class based on database schema would be very hard, very long, very bugable and would break static checkers so I am pretty sure they never exist.
I have an existing sqlite db schema (about 30 table) which I have to import into my Android project.
I'd like to use greenDao in my code but I don't know how it's possible if I have already sqlite db created.
Is it possible to work with greenDao even if I haven't my pojo/entity class generated by greenDao Generator? Could I generate them manually?
I think I need also DaoMaster and DaoSession!??!
Thank you very much.
I've never done it, but theoretically, yes you can.
From greenDao FAQ page:
Can I use existing entity classes? Can I skip entity generation?
Yes. In your generator project, call setSkipGeneration(true) on entities you do not want to generate. Like this, you have the most possible control over your entities at the cost of manual maintenance. However, this is considered advanced usage and should be reserved for special cases only: the recommended way is to generate entities and use “keep sections” to inject custom code into them. If you choose to skip entity generation, you must either provide a constructor with all property fields in the order they were added in the generator project. Or alternatively, call setConstructors(false) on entities to make greenDAO use setters instead of the constructor to create entities.
I understand that you have to implement the generator project normally but skype de generation of the entities. This should generate the DaoMaster and DaoSession only.
I have ben following through a tutorial that shows how to get started creating a Web Forms Application in ASP.NET...and have got to the part where you create Data Classes. These assume you are starting from scratch and generating the database from code - however - I already have a database created and populated from elsewhere.
Entering line by line to create the Class for each table seems very laborious. (I'm using VB.Net and VS 2013 by the way)
Q1. Can anyone help by suggesting a more automated way of doing this? Surely there is a tool to grab the schema?
Q2. Although the tutorial mentions Entity Framework and Code Behind briefly - having done some reading and research - I am very confused by all of the different terms for data access. Am I using ADO.NET ?? Is the methodology called Code Behind as opposed to something else? Are there better ways to connect to a database and Read/Update/Delete records.
Q3. If I want to use a Data Grid to show the data do I use the generated classes to do this - or just 'bind' the grid directly to the database?
I have been a developer for 40 years but the newer .Net models are causing me some confusion so any advice gratefully received. (and any simple books or tutorials that can be suggested would be helpful).
Thanks
Q1: What you want is to generate "EF Designer from database" by using a Entity Data Model.
In your project add a new item and look under "Data".
What this technique does is auto generating entity classes from your predefined database.
Q2: I suggest you read Getting started with Entity Framework. "Database First" is just a description of how you want to use the Entity framework - by saying you already have a database structure.
Q3: In this case if you use Entity Framework and the "database first" mechanism to generate entities you can databind the gridview from the result of a entity LINQ query, please see this example: Tutorial: Databinding
I just started learning about asp.net mvc. My previous expierence is in python django. I was wondering when I make classes in the models file, it will automatically create those tables for me? Sorry I am a real beginner.
No, It just maps your input data and enables controllers to manipulate data and send to view. In order to fill data into database you should use LINQ to SQL and data entity framework.
Is it a bad idea (and if why?) to add a a column to the auto generated asp.net (ASPNETDB.MDF, visual studio 2008, mvc framework) "user roles - database"?
(E.g I want to add the columns RealName and LastName to the aspnet_Users table in the database.)
The reason I want to add a column instead of creating an entire new table is to avoid the doule maintenance issue and unnecessary redundancy
There are two generation schemes that are used (from Pragmatic Programmer):
Those that are used once to generate code
Those that are used all the time to have some code synced
The ones that are used for syncing, the results should not be modified, since they could be overridden at a later date when the generation gets done again.
In the case of your generated asp.net database, there is no reason for you to rerun the generation, so it would be OK to edit it.
The only scenario under which you would rerun the generation of the db is if microsoft releases a new version of the users database and you want to use the new one (in this case you might have to edit some parts of your application, so you could readd those two fields), or if you want to regenerate the database with different options. Both of these happen if you are not happy with your current db.
In my opinion that autogenerated database should be replaced by a normal table in application database or at least there should be an official solution to this problem.
I heard that this is quite good solution: http://www.asp.net/downloads/sandbox/table-profile-provider-samples/
why dont you create a new table with a Foriegn Key restraint? It seems like a bad idea to add a column to the aspnetdb...it will be a nightmare if you ever need to recreate your db...
First, those tables aren't really anything specific to MVC: they're created by/for the default AspNetSqlMembershipProvider. (Also applies to other kinds of ASP.NET applications.)
You could probably add new columns safely, but the membership provider wouldn't "see" them. It does provide its profile mechanism to store extra information (which gets serialized, and stored in the aspnet_Profiles table).
If you need to store lots of additional information about the user, you might also check out this sample membership provider that stores profile information in first-class tables, rather that in profile blobs.