Recently I did one web site (www.ramtajogi.com) using asp.net mvc, linq to sql .
I have used repository pattern to get data from the database. Now everything is working fine.
But the new requirement is to record all the events (on poetry book created, on poem added or when a new comment is posted to any poem. What is the best way to implement it.
Should I change my existing classes and do or is there any better way to do it.
Regards
Parminder
I think what you are looking for is a way to log across different actions:
Try this: http://www.singingeels.com/Articles/Logging_with_ASPNET_MVC_Action_Filters.aspx
Maybe you want to go the "SQL Trigger" road? I know it's a much debated subject, but it allows you to log without changing any of your existing code.
I'm not sure about its impact, but if the triggers only do some inserts into a log table, I guess it should be quite low.
Thanks everyone,
Actually I created another table for alerts and added one record for every event.
Regards
Parminder
Related
I'm working on a new project that will let users create new party event through a simple form and I need that data stored as a new table for each new event. What I wanted to know is if its possible for user to create new table in my Database by submitting the form? I know that you can write data to columns, but I have no idea if you can actually write an actual table with columns.
I'm working with MVC 4 and this is sort of new to me and I'm not sure if such thing is possible so wanted to check to make sure before I move to alternate path.
Thanks
First off: STOP USING THAT DESIGN
Read this page before you go any further too: Database Normalization
the schema for your database should looks something like this:
users
id,name,etc...
parties
id,user_id,date,etc...
Using your way you will run into MASSIVE problems down the road
What I wanted to know is if its possible for user to create new table
in my Database by submitting the form?
Of course that it is possible. If you couldn't insert records in a database after suibmitting a form in ASP.NET MVC, then this framework would be useless garbage.
I know that you can write data to columns, but I have no idea if you
can actually write an actual table with columns.
You may take a look at plain ADO.NET or an ORM such as Entity Framework which both allow you to query a relational database. By the way you might consider reading some of the getting started tutorials on the http://asp.net/mvc site. Here's one example you might go through.
yes, you can write SQL DDL Sentences. "CREATE TABLE" is the concrete expresion you need to use in this case. It may takes different syntax according the database you are using
I got an online website written in ASP.MVC. Now, i need to periodically check one table, and if it changes, i need to take further actions related with modifying data in other tables. I could of course write a stand-alone application that would do that for me, but what other options do i have? I am asking, because maybe there is something better which i don't know about.
Assuming that you're using SQL Server, one option would be to add an item to the ASP.NET Cache, and then register a SqlCacheDependency on that item for the table or row that is to be monitored. There is a bit of configuration required to get this up and running, some instructions are here (with the code samples being in VB). When you add the item to the cache that has a SqlCacheDependency, you can specify a callback method that is fired when the data changes, which is how you would update related tables. If you are running SQL Server, want a pre-defined solution provided by Microsoft, and don't mind the setup process and additional database tables and configuration that this includes, this would be a great option.
I got an answer that is satysfying my requirements. There is something called Quartz.net that works just as i wanted it to. :)
I am using Entity Framework code first, so keep dropping and re-creating the database. My asp.net membership tables keep disappearing as well - particularly annoying on the build server.
The best way I have found to create the tables so far involves a post build event running aspnet_sql.exe, but the connection strings need to be hard-coded and its making staging-release environments difficult.
Is there an elegant way to create the tables in code?
Have a look at Universal Providers. Then you don't need to use aspnet_sql.exe.
Also use migrations rather than drop and re-create database.
Why are you dropping and re-creating tables so often? Maybe migrations could solve this issue for you.
How to fetch all data required for processing a request in one call to DB. Also I want to know how will I do this if my master page also requires some data from database? I know that its clarified in Passing data to Master Page in ASP.NET MVC. But I think that will make multiple calls to database. Please let me know if it's not like that.
UPDATE
+1 and thanks to all answerers/commenter s for their views and advice.
I think you might be confusing one session per request and SELECT N + 1 scenarios. It is perfectly fine to have multiple calls to the database, however you want to watch out for when you have to do one database call per item in a list. This is most commonly encountered when using lazy loaded lists. The solution is to use eager fetching.
ps. I think the popular solution for getting data to the master page is to use Html.RenderAction in the master page. That way you don't have to worry about master page concerns (like navigation) all over the place.
I have to agree with the other answers, what is your justification for this?
NHibernate can batch SQL statements using FUTURES, have you read this blog post?
However said I am not sure how you would combine all possibilities for all of your views on your site. If you do come up a solution I would love to see it.
This is not going to be easy and showing a small code example is not possible.
It's a bit of a tall order to limit yourself to only one database hit per request. What are your reasons for doing this? Is it just a fun challenge you've set yourself? If it's for optimisation reasons, there are better ways of achieving this: optimising queries, caching etc.
I want to develop an ASP.Net MVC application with EF4 Model First design and only generate the actual database much later, ideally at the end of the project.
Based on some of the ideas here:
http://elegantcode.com/2009/12/15/entity-framework-ef4-generic-repository-and-unit-of-work-prototype/
I want to create something like an InMemoryObjectContext for testing and development and use IOC to switch to the SQL Server implamentation (EF generated) for UAT and production.
Is this wise?
Is it possible? If so, does anyone have any suggestions?
Does EF always need an underlying database in order to track changes, commit etc?
I've tried creating a model first but as soon as I add properties I get the following errors:
Error 2062: No mapping specified for instances of the EntitySet and AssociationSet in the EntityContainer Model1Container.
and the warning:
Running transformation: Please overwrite the replacement token '$edmxInputFile$' with the actual name of the .edmx file you would like to generate from.
The error doesn't stop the application running but worries me. I'm very very new to EF so I apologize if this is way off the mark or a dumb question. I'm hoping to get some good advice while I sit for the next few days and watch videos and read articles.
Thanks
Davy
At the very least you need mapping information "filled in". You can fill these fields with nonsense if you don't want to work against the underlying database.
If your doing Model first, right click on the designer canvas and select, "Generate Database from Model". This will automatically create convention based mappings for you without defining tables and columns. You don't even need a valid db connection to do this.