How to develop project using T4 template that can create database,database tables etc like entity framework works - t4

I want to use T4 template for generation of code,that can take input from windows form and create my projects depend on input of form.I want to create database,database tables like entity framework create the database module for us.
Thanks in advance.

Use T4 templates in runtime mode:
https://msdn.microsoft.com/en-us/library/ee844259.aspx
Collect your data from form and pass them to T4 template (in constructor for example).
Constructor create in partial class for template.

Related

Pulling s_categories table from database to someone.tpl in shopware 5

I want to pull the data from the s_categories table in the database to the tpl file I want and use it as an array, but I couldn't find how to do this in smarty. (Note: {php}{/php} doesn't work.)
You can't do that in smarty, you need a plugin that provides this data to the template to use it there. Smarty is a template engine and should not be used for accessing data from the database - this is the wrong layer of the application to do such things.
All things are covered in the plugin startup guide: https://developers.shopware.com/developers-guide/plugin-quick-start/#search-results

Learning Laravel blade standalone

I'm pretty new with blade template building in Laravel and I'm planning to use it as standalone. What's the best way to learn blade template building perhaps for standalone?
What's the different components of blade template building and what's the data flow?
If you want to use without Laravel, then you could try my library.
https://github.com/EFTEC/BladeOne
Its stand alone, only one class and no dependencies (and mit license)
The docs about blade is here
https://laravel.com/docs/5.5/blade
The data flow is simple:
add all the libraries and dependencies.
creates all the
variables, collects information from $_POST,$_GET and such.
Load
and do all the operations, such as loading from the database,
inserting, doing some operation.
And finally, call the template and send the variables. The template must be called at the end of your script. Always.

How to use one database in two .Net core MVC and Web API projects?

I've create two MVC and Web API .Net Core projects in one solution, in first project i've added model Phone and DataContext for it, made migration and update-database. In second project i've added equals connectionstring,model and DataContext, but when i try make the update-database i get the next error:
There is already an object named 'Phones' in the database.
Tell me please the right way how to configure database, datacontext and models in two projects to use one database ?
If you use two separate DbContexts, each with their own migrations, they'll consider the database to be theirs and reapply the changes that the other project already did, resulting in conflicts such as the one you observed.
Simply move the Entity Framework code into a shared class library and reference that library from both implementing projects, so all state about the database is shared.

How to Share Models Between WP7 and Azure Projects

I have a WP7 project, which will invoke a REST web service in Azure (MVC4 WebApi).
My WP7 project has models that it serializes to JSON and then sends to the web service.
The web service deserializes the data sent from WP7 and instantiates the models again before saving them to Azure Table Storage.
How can I share the Model classes between the projects? Right now I'm just copying the cs files over, and I have to update both sets if I make a change to the models. I was hoping a simple class library project would be able to be referenced from both projects, but WP7 couldn't handle that.
What should I do?
Thanks!
There are many solutions for this issue:
You could use a T4 template to read the entity and generate a class your WP7 project that only contains the properties of the object without reference to the Table Storage specifics (like TableStorageEntity): http://weblogs.asp.net/cibrax/archive/2009/03/11/code-generation-with-t4-an-entities-to-dto-example.aspx
You could split your entity over 2 files, one with the TableStorage specifics like TableStorageEntity and one file containing only the properties of the entity (use partial classes for this). Then you can add the file containing only the properties in your WP7 project as a link.
Create a DTO (or whatever you call it) class manually and use something like AutoMapper to map between the DTO and the TableStorage entity. Store the DTO in a portable library so it can be used by every kind of project. In my opinion this is the best solution since you don't want to completely expose your entities to "the outside world". An example would be a list of users. You wouldn't want to return all fields including password, hash... and other sensitive info. It would be better to have a separate class that only contains the info you want to expose externally.

Reorganizing codes after generating it using ADO.NET DbContext Generator

Suppose I am creating a application using the sample Northwind database using asp.net mvc 3 and entity framework database first approach. For that I am opening a new asp.net mvc 3 project and then adding a ado.net entity data model. I am generating it from the existing database as it is already created. After that I am using the ado.net DbContext generator to generate codes for me. These includes all the models and the DbContext file(in this case NorthwindContext).
Now the problem that I am facing is in reorganizing the code. All the models should be placed in the Model folder of the project. Even if i generate the codes in the Model folder the NorthwindContext class is also generated in it. That is under the NorthwindContext.tt file a NorthwindContext.cs is generated. This file should reamin in the DAL folder as I will use it for accessing the data. Now if i just drag an drop it into the DAL folder the code generation stops automatically(no code remains in the NorthwindContext.cs file). Any idea how i can resolve this problem?????
There are a few hoops you need to jump through to get this setup.
You should have two T4 templates generated, one for the model classes and one for the context. Move the T4 template for the model to your model assembly then open it in Visual Studio and update the file path back to the edmx in your data access assembly. Edit the context T4 in the data access assembly to emit a using statement for the model namespace. Finally add a reference to your model assembly in the data access assembly.
Whenever you want to regen the classes right click in VS and select Run Custom Tool for both the Context and Model T4.

Resources