Subsonic Question, is it possible execute templates during runtime? - subsonic

Before ask my question, i have to say that subsonic is wonderfull tool, i realy like it.
I have an application which is createg domain layer during the runtime itself. I mean It has got customizable entites and when the entity added or any entity schema changed my model layer compiled again in the runtime according to changed database.
I'm wondering that, is it possible to execute subsonic templates during the runtime or when the user changed enetity schema or add to new entity to the application can it automatically generate the model layer again ? or how to trigger the template during the runtime of Subsonic ?
Thank you

If you make some modifications to the templates you can use the TextTransform.exe command line tool to generate SubSonic classes as described in the following answer:
SubSonic ASP.NET MVC sample in Visual Web Developer Express
You could then automate the execution of the commandline when your user modifies the schema.

Related

Where does Orchard CMS stored content definition?

I am fairly new to Orchard CMS.
I am going through how a module is created an got a question.
According to the documentation, content definition could be created in two ways:
use admin content definition page
create module project in visual studio
is there any difference?
I created a test content definition and try to find it in the SQL compact database. I can't seem to find it.
Anyone know where that info is stored?
Thanks
You can find the content definition in the following tables in the Orchard database:
Settings_ContentFieldDefinitionRecord
Settings_ContentPartDefinitionRecord
Settings_ContentPartFieldDefinitionRecord
Settings_ContentTypeDefinitionRecord
Settings_ContentTypePartDefinitionRecord
The admin interface uses the same APIs that are used when defining content definition from code, so it's basically the same thing. I tend to define content definition in migrations, as that's the best way to ensure that content definition changes are properly applied on all instances of the application (the migrations automatically run during application startup). The admin interface is intended for users who do not have access to the source code (ex. administrators, not developers).

MVC 4 unable to perform scaffolding

I'm new to MVC, and my intention actually is to learn 'Code First' technique, using MVC 4. I'd been through several 'MVC 4 Entity Framework' tutorials, and no doubt, tutorials are really simple, and understandable. but for every tutorial I followd, the
EF will look for the database in the default location and if it doesn’t exist, it will create it for you
part is not working for me. Do i have to add ADO.net Entity framework model in project, and design the database entities firt? or am I missing something? It's been more than 15 days, & I'm stuck.
(I tried making database manually first, and it worked perfect. But I want to learn, as described in tutorials, that databases are automatically created, if we mention the connection string, and EntityFramework finds out that path doesn't actually contains such database, so it creates one).
I'd been through several tutorials, let's say, I'm following THIS one.
(I'm using Visual Studio Express for web 2012, EF 5.0.0)
your question: Do i have to add ADO.net Entity framework model in project, and design the database entities firt?
yes, in code first approach you need to tell entity framework what tables you are going to create, you do it by creating poco classes(Plain old CLR Object). then in run time entity framework will create a model(witch is a xml file) and generate query according to that xml file then executes it. you can read more about that in [CSDL MSL CSDL][1]
so for summary you write your domain classes(poco classes) and ef will create db for you but btw there is another way where in entity framework code first witch is called [Code first to existing database][2]
[2]: http://weblogs.asp.net/scottgu/archive/2010/08/03/using-ef-code-first-with-an-existing-database.aspx it revers engineer the databse and create model for you.
Do i have to add ADO.net Entity framework model in project, and design the database entities first?
This is really the more traditional approach, aptly called the database-first approach. The code-first approach is an alternative to the former. They mean exactly what they say. In the case of code-first the code is first written and in effect the database is generated automatically. In database approach, the database is first created then you can use EF to automatically generate the code required to handle the database, mainly CRUD and connection management.
The built-in scaffolder in ASP.NET MVC should work fine either in code-first or database-first as long as you have your models already established in your project. If you find the generated code too simplistic, an alternative scaffolder that you can use is CamoteQ - it is an online ASP.NET MVC scaffolding tool that is based in DDD principles and recognized patterns.

VS 2012 EF 5 using .net 4 and database first Layered applications concepts

I upgraded from VS2005 to VS2012 specifically to code in .Net 4,.Net 4.5, and use EF5. I am new to EF. I have Julie's EF book but it talks mainly about EF4 and POCO and it has me confused trying to implement EF5.
My hosting only allows me to run .Net 4 currently. I am trying to use EF5 on a new database.
I tried Code first to generate my database but I could not get it to generate the database. So I created the database first and then generated the model from the database with EF5. What I want is a layered website using ASP.NET Forms, Data Access Layer, and a Business Layer. The business layer I intend to build so I can use ObjectDataSource to pull in to the webpage along with some web services to use cascading dropdowns.
I have my NameX.edm model created but the tt files don't have the same names, they have Model1.tt and Model1.Context.tt is not the same name, why. Also Model1.Context.tt is empty. I am attempting to create the POCO classes running the EF5 DbContext but I am having trouble getting it to see the edm model. I read somewhere that EF5 creates the POCO automatically. I am not seeing the big picture here. Is my issue that I am not using .Net4.5?
What I have is a ASP.NET Application project, a EF Project, a POCO Project, and intend to have a forth project with the Business logic. How do I get the EF generated correctly and the POCO classes? I want a layered application for to scale well. Next question How to get the POCO classes to talk with the Business logic? My database is SQL. I am use to writing stored proceedures to accomplish everything through business logic.
If you are using Model First technique, make sure that you have references to System.Data.Entity and System.Data.Entity.Design. Also, you will need to create a reference to the EntityFramework.dll as well. It is located by default in c:\Program Files\Microsoft ADO.NET Entity Framework Feature CTP5\Binaries\EntityFramework.dll. If you can not find it, make sure you have installed the Entity Framework through your Package Manager Console. To do this, open up Tools, Library Package Manager, Package Manager Console, then type Install-Package EntityFrameWork.
Next you want to add a new item to your project. Right click on your solution, go to Add, then select New Item. You want to select Data from the Common Items section on the left, then select ADO.NET Entity Data Model.
Next Select Generate From Database. In the next screen, if you have not set up your connection to the server, click New Connection..., otherwise select your database from the drop down box. You need to select whether or not you want to include your connection string information in your config file. This is up to you how secure you need your application to be. If you choose not to, you need to pass this information as parameters in code. Also at the bottom, you will most likely want to change the auto-generated entities name to something easier for you to use. This name will be the name of your DBContext Class!
Next you want to select the tables you would like EF to create POCO's for. If you want all the tables just tick the tables items. Same goes for views and stored procs.
Once you click finish, then you should see all your fancy POCOS laid out in front of you in Design Mode. Note If you do not have primary keys in place for all your tables, I suggest you fix that! VS will spit at you if you do not have Primary Keys set, or if your naming conventions in your tables prevent VS from creating them for you implicitly.
This is a quick little tutorial on getting you up and running. You can now persist and pull data from your POCOS by using your DBContext object. For example if you named your DBContext class *Gary_Bettman_Sucks*, and you wanted to create a new record from your table called NHL you would do the following:
Dim context as New Gary_Bettman_Sucks
Dim PullMyGoalie as New NHL With {
.Goals = 0,
.Playoffs = False
}
context.Set(Of NHL).Add(PullMyGoalie)
context.SaveChanges()
I would Highly suggest you look into implementing the Repository Pattern with your design to encourage code re-use, and it will seriously make your life MUCH easier down the road.
Hope this helps!

How do I use SimpleRepository without the migration approach?

I am evaluating SubSonic for use in Phase 2 of a large project. This is an ASP.NET project, with 700 tables in a SQL Server database.
We are planning for our domain model to consist of POCO classes to assist with an offline access requirements we have. I believe that the SimpleRepository pattern would be among my best options.
Since I have a database already, however, the migration assistance doesn't help me. Are there T4 templates for SimpleRepository that I just overlooked? How do I 'turn off' migration? If I missed something in the Wiki, point me there, otherwise get me started and I'll write up a Wiki entry for y'all when we get there.
I'd suggest you look at the linq templates. They're generated from your database just like the ActiveRecord templates but give you POCOs instead.
Alternatively you can just use the simple templates and never run migrations, migrations only happen when you explicitly tell them to (by specifying SimpleRepositoryOptions.RunMigrations while creating your repository) so it's not so much that you need to turn them off, just don't turn them on.

schema changes and subsonic - VS 2008

I have been using subsonic and the issues i keep running into is with when i make schema changes, I have to recompile everything and at times subsonic does not recognise some of the schema changes.
Is there a better OR/M that i can use asp.net which is more efficient with working with schema changes
I never had any problems with class generation with SubSonic. Are you sure your schema is a good one? Do you follow the conventions? If some tables are not generated, you may be missing PKs, but if you look into the generated classes it will tell you (in a comment) that this is the case. That's all the advice that I can give based on the information provided by you. I still think it's not SubSonic that's the problem...
If you are using the BuildProvider there is known issues with that and you might have to edit the web.config sometimes for it to rebuild, you can also try using SubCommander (sonic.exe) to generate your classes for you.
You can also try NHibernate check out http://www.summerofnhibernate.com/
What Database are you using and what schema changes are not showing up. In my experience with SubSonic I have never had any schema changes not show up in the generated classes. The largest error that I have seen people make is to add a table to their database, run the SubCommander to generate their classes and then forget to include the generated class in their project.
The only other related issue I have seen people make is if you generate your classes in a seperate class and they are all generated in C# and the project that is using the classes is written in VB. VB can not read into a C# project so you first need to build your C# project to see the schema changes in your VB project. That is one of the limitations of VB.
I suggest LLBLGen PRO. It is not free but well worth the $$$. I have been using it for more that 4 years on both web and windows applications.

Resources