ASP.NET MVC & Entity Framework - entity-framework-5

We have a SQL Server with multiple database (different schema) and i need to develop an application in ASP.NET MVC & Entity Framework to connect to any of these database in runtime and perform DML operations. If a new database is added to the SQL Server then the application should able to connect to this new database without any configuration/code change. I am exactly looking for DML operation handled by myLittleAdmin
Can anyone advice me on this please

Unfortunately you won't be able to do this with Entity Framework. Entity Framework operates in two different instances, Code-first & Database-first.
The former being writing your relevant model classes for your data first and then Entity Framework will work out a database schema based upon those classes handling foreign key references etc automatically based on the references between models.
The latter is effectively the opposite, you define the database schema and Entity Framework produces the model classes from this. I have always found this method to be cleaner as you have more control over the database structure and I find it more difficult to make mistakes.
In your situation Entity Framework needs to know before hand the structure of the database to enable it to read from it so it cannot "connect to this new database without any configuration/code change". If you can provide more information about what you are wanting then I may be able to help.
I recently created an asset management system which could store generic assets which would traditionally be stored in separate tables, this solution was developed using Entity Framework but the database was designed in such a way that it could handle generic asset objects and store them i.e. if we created a new asset type then no database change was required hence there was no code change for Entity Framework either.

Related

Multiple web services sharing single database using Sequelize

I'm trying to make a service architecture which includes two Node.js apps which shares the same database. The overall service architecture looks like below (simplified version)
I'm planning to use Sequelize as an ORM to access the database. As far as I know, if a service uses Sequelize, it needs model to get the structure of data tables. In my case, api and service will access the same database, which means they should share the same Sequelize model.
So here is the question: where should I locate the common Sequelize relevant files? It seems I have two choices:
put them on the upper common location (assuming the project structure is monorepo) so that each apps can use the single same files
maintain copies of files in each apps' project folders. In this case, each apps will be independent(Let's say I want to dockerize each apps) but in case the Sequelize files modified, the same action should be done for the other.
I'm not sure how I understood is correct. Is my question valid? If so, what is the better choice and practice? I appreciate for your answers in advance.
There is no correct answer, it depends on the specific situation, but sharing a database between multiple microservices is a bad design.
Sharing a database means tight coupling at the data level. The direct consequence is that when a service modifies the database table structure, such as deleting the name field of the user table, it may break the APIs of other services and all use the sequelize user model. All services need to update the model definition and modify the implementation code of the API.
If all of your services are maintained by a team, I suggest you choose the first solution, which costs less and is easier to maintain. If your services are maintained by different teams, the two solutions are actually similar, because as long as the table structure is modified, the application layer model needs to be modified or verified whether it still works well.
Therefore, I recommend following the best practices of microservice architecture, first splitting the database vertically according to the business model, and building application APIs on top of it.
Core principles of microservices:
loose coupling
high cohesion

Liferay Service Builder : how to use hibernate session factory for relation

In my project i have multiple liferay plugin portlets. I have used single plugin in portlet having service builder. All other plugin portlets are using same service builder portlet.
Ex:
Portlet1, Poertlet2, Portlet3 and ServiceBuilder portlet. Portlet1, Poertlet2, Portlet3 are using same ServiceBuilder portlet.
This service builder is connected to external database. And i am inserting/fetching data from this external database. There are one to many and many to one relationship structure in database. I want to use hibernate relationship model for these relationship and run complex queries to fetch data. So i want to use hibernate session factory in my service builder.
Please give your valuable advice or code so that i can do this as per the requirement.
Please note:
1. I have read about liferay relationship in tables. But this has not work as per my requirement.
2. Most of tables are managed by other application. I am using their data only.
Service builder does not work this way and if you want the relation you should not use it.
The idea behind service builder is to have an easy DB access layer - entity at a time and the relations are resolved in the business logic.
If you want that the relations are handled by the persistence layer you need to use plain hibernate.

Two nodejs applications, one mongodb database

Good day! I have created an application using nodejs + mongoose and now I want to make something like a superuser application. I need my admin panel application to connect to the same database. So, i have a question.
Should i store the same Schema file in both applications to have an ability to use my Schema methods? In other words, what is the best way to create one more API using the same db?
Thank you!
If I'm not mistaken, why not create another service that only interacts with the database? That way, the systems will refer to the same schema/DB regardless of which application you want to connect to it. So the superuser application and the normal application will just query the DB microservice that interacts the database.
Pro: source of truth for the schema for all applications and the DB queries will just be API calls
Con: additional overhead in creating your ecosystem
If you are using the same DB from two different applications, you will want to make sure those schemas are the same between the two. If one changes its inputs, the other might need to change its display (or risk not expecting all that information). Keep all this in mind during your release process.
I would suggest making the schemas an external library to both, or have the admin panel require the current app. You'll avoid getting two sets out of sync and know to look at one place for the schema definitions.

Liferay Portlet: How to generate service.xml (service builder) from existing database

I am new to liferay, Can anyone please suggest some way to generate the service.xml for existing database Discussion on Liferay Website . I hope people might have developed some way or liferay have developed some plugin for this.
I see no particular use in introducing servicebuilder to large existing databases: You can connect servicebuilder entities to "legacy datasources" or "legacy tables" (those make good search terms) but service.xml generation has not been done AFAIK.
Some problem with this approach are:
servicebuilder has certain assumptions about operations in a database. It's done to encapsulate all different databases that Liferay runs on, thus might not use every database to its fullest extent possible
If you have a large existing database, you probably have a lot of existing business logic to make sure correct data goes in and out of the database. You might even work with stored procedures etc.
While you can make servicebuilder work with stored procedures, you'd have to introduce custom sql to work around servicebuilder's assumptions. Same goes for explicit foreign key relationships etc.
My recommendation is to rather have a proper interface on the existing business logic, e.g. Webservice, JSON, Rest, whatever is popular. Then use this interface in Liferay's portlets.
Another option might be to bring the existing persistence code into Liferay and just expose services without making use of the persistence features of Servicebuilder. For this you'd just define empty <entity> blocks (with names etc). This will generate the appropriate DoSomethingLocalService, but omit the persistence implementation - and you can wire your existing code in these services.
You can go through below link to understand Service Builder in liferay
https://www.liferay.com/documentation/liferay-portal/6.0/development/-/ai/service-build-2
Also below link have sample service builder portlet
https://www.liferay.com/community/forums/-/message_boards/message/17609606
Hope it Helps !
Not done yet AFAIK. Since Liferay directly doesnot support all data properties of DB like foreign key, one to n mapping etc, it is a challenge to create the reverese engineering. But you can give a try.
Service Builder is generally a nice feature to create relatively small databases, and simple business Logic, while giving you the advantage that your tables will be auto-generated when you deploy your portlet, and having finders (search by X attribute) with no effort. If this is the case with your database, it will be much easier to create a new service.xml from scratch.
Other that that, I think that having an extended database in Liferay's Service Builder will introduce more problems and slow development while you're implementing a complex business Logic, create custom Finders whenever you need to query on a join of tables and so on. So it seems quite normal to me that a conversion of a database to Service Builder is not available.
In other words, if your database is too large to write it in service.xml, you shouldn't use Service Builder in the first place

SharePoint List like Data Access Interface

I am impressed by the way we programmatically access lists in SharePoint. I percieve it as a Data Access Layer, while modeling the database is as simple as defining the columns in the List.
I am looking for a tool OR an application that would give me similar interface to a database. Basically, for some reason I cannot use SharePoint and I don't wish to take up the responsibility of modeling, deploying and maintaining the database. I find the SharePoint way of persistence management acceptable and exciting.
Can anyone suggest me something even close to this.
BTW, my application is on ASP.Net and my preferred RDBMS is MS SQL Server.
If you don't want the overhead and expense of a Sharepoint installation, 90% of the time all you really need is WSS 3.0 (free with a windows server license).
For auto generated entity classes you can use Linq To Sharepoint (SPMetal)
For hand written POCO entities you can try using SharepointCommon ORM
Use NOSQL database like MongoDb or CouchDB which are schema less, allowing you to freely add fields to JSON documents without having to first define schema.

Resources