Implementing Navigation Properties in Entity Framework - asp.net

Hey folks,
I've been learning MVC 2 and I have pretty much everything understood except for the model part of things, I understand what the model is but actually implementing it has me confused.
Here's my situation, I have my DB which has 3 tables;
Ideas - table of ideas
Tags - table of tags
IdeaTag - link table connecting the above 2 tables via FKs
So when using the Entity Framework (.edmx) designer in VS2010 I get 2 classes created in the Designer, which obviously map to my DB tables and Navigation Properties in Idea for Tags & Idea for Tag.
So this is all fine until I actually try to add tags to an idea, what's the best practise for dealing with Navigation Properties? I wanted to add a Textbox which will then map to the Tags property in the Idea class but I'm unsure how I'd go about this.
Most of the MVC tutorials which discuss EF or Linq to SQL are quite basic.
If there are any suggestions for tutorials or video tutorials which discuss dealing Navigation Properties and how best to deal with them I'd gladly take it on board. Alternatively if there is a better way to implement this I'd happily look into that too.

Seeing as this is basically a Many to Many relationship, check out the accepted answer on this question.
It covers the scenario you are looking for. In your case 'ID' is probably the actual tag, i.e. "Entity Framework" or something.
Using the approach in that sample you can have a textbox, with a comma (or something else) delimited list of tag names. Splitting the contents of the textbox gives you an array of tags that should be in the Idea.Tags collection after you're done.
The only complication you have is I guess, you want to automatically create 'new' tags. So perhaps you'll probably need to check whether the Tag exists before attaching it (to add it to the Idea.Tags collection), if it doesn't exist instead of attaching it you would simply add it, so the new tag gets inserted.

Related

Design tips for a search engine in asp.net/asp.net mvc which vaguely resembles a sharepoint view

Guys i am looking for some awesome tips for developing a page which allows users to search for stuff from the db with the view restricted to only certain columns and the data grouped by and sorted by certain columns..
the source in this case is pretty easy to figure out which is a class which retrieves the search results...kapish..
the view in this case is giving me nightmares as i do not want to write that disgusting piece of code which many asp guys are seemingly used to...overriding row created and data bound of gridview etc etc.... i am thinking of simply rendering a html table itself with the necessary preprocessing applied at the datatable level(group by, sortby etc etc on the in memory object retrieved from the paged results)
i need to know if my thought process so far is right or is there a cleaner way of doing the whole thing in asp.net/asp.net mvc etc etc
Congratulations for not wanting to write "disgusting piece of code"... I spent a few years doing just that and the whole overriding row created / bound / etc. thing is a nightmare.
Your source is a class - great. My preferred method would be to go down the jQuery route, use the jqGrid and write an MVC controller that uses your custom class. Or you could dynamically generate your own HTML table but if you have a lot of data I would save yourself the time and explore jqGrid instead. It doesn't have to be MVC - you could embed it into a standard asp.net website, it's just that the MVC approach makes life easier if you have to expand your application to do more things.

How to implement tags in Symfony 2?

I would like to have a form for entering tags (like the tag symfony2 in this post). Something like the field below would be great, but for starting it would be enough to have a text field with semicolon (;) or comma (,) separated values that go into an n:m relationship in a database.
Unfortunatly it is really hard to search for this, as virtually everything contains the word tag :)
There is a bundle that does most of the heavy lifting for you...
http://bundles.knplabs.org/FabienPennequin/FPNTagBundle
You will have to implement the client-side form control (jquery based probably), but could use something like jQuery TagIt
This may also be what you're looking for:
How to Embed a Collection of Forms
You might use the MkTagBundle:
https://github.com/Mykees/MkTagBundle
It contains also a seperate website for documentation here:
http://mykees.github.io/MkTagBundle
By the way, it contains a number of other bundles.

ASP.NET Need advice in making a very simple comment page using listview and peoples username

I have a asp.net site that is nearly complete.
I have the ability to register and log in.
I want to add a page where reigstered members can make a comment that is saved to a very simple message board (possibly a guestbook type thing).
How can I do this... would using a gridview/listview be a good idea?
I have created a table for the use saving messages to a database. I have basically the following fields:
MessageId (PK), UserID (FK), Comment, Date
How hard would it be to implement this? am I going down the right path?
Thanks in advance,
Jason
Many options.
I would consider the listview -- it is by far the most flexible and powerful. You can have it render tables, divs, lists, or whatever you like. Much more flexible / easy to style and layout. And if you ever decide to make your comment list more interactive (such as collecting reactions to comments, rating, or whatever), I think it will be a lot easier to modify layout than some of the other controls.
MSDN magazine made a case for it a few years ago -- http://msdn.microsoft.com/en-us/magazine/cc337898.aspx.
Also, here is the MSDN on it -- http://msdn.microsoft.com/en-us/library/bb398790.aspx

Having a UI layer and presentation layer

Let's say I'm on a list page and I
page to, say, page 10. Then I select
a record on that page and redirect to detail
page. After that, I click on the edit
to redirect to the edit page.
After I update the record I'm redirected back to
the detail page. I, then, press back
to go back list to continue my browsing from
where I left off. The key here is
where I left off in the list which is
page 10.
What is the best way to handle this?
Initially, I put a hidden field called page number in each of the webforms and pass it along with the querystring back and forth. Seemed like a lot or a bit redundant checking the querystring on each page and passing it.
I was wondering if there are some other ways. for instance, I've been reading about a separation between the UI and the presentation layer is a good idea (for larger scale apps). To me I understand it as all click handler events will yield control over to the presentation layer which is just a plain class?
Is this correct? Also, is the presentation layer suppose to implement something particular? I know this could probably be saved in session but could someone humor me and show me how to use a presentation layer to handle this (I know it would be overkill but is it possible?)
I don't think there is THE best way. Everything depends of what you achieve to do, ie. the requirements of the whole project.
After all, according to the description, I don't even understand why are you having three pages to do a single thing. By the way, ASP.NET data controls handle mostly everything for you, so you don't even have to ask yourself how to do this (except if you have serious reasons to avoid ASP.NET controls).
For example, a simple <asp:ListView /> will let you list items page per page and show details when a single item is selected. Edition of an element is also quite easy.
What you are asking for is well... large and could span multiple blog posts to give a complete understanding of UI Design Patterns.
I have a small example of MVP with Asp.Net here: What is the best way to reuse pages from one website in another?
However, it is not exhaustive. If you really want information on this you should do some looking into a framework such as WebForms MVP, or ASP.Net MVC.
Check out ASP.NET MVC. It is a framework which goes on top of ASP.NET to do the separation between the presentation layer and business layer.
For simplicity, what you are describing is a very good example of the perfect place to use Asp.Net Dynamic Data.
It's incredibly easy and powerful, and easy to modify once you dig into it a bit. I'd start with the videos here: http://www.asp.net/dynamicdata
I've been using this more and more on every project, for at least the simple CRUD portion of it. I really can't express how much I love this tool now that I'm used to it.

How to insert values into database?

I have taken some text field and abd some labels and one submit and one reset button. I want to code like: when i enter some values in text boxes and click upon submit my record will get submitted into the database. And when i click upon reset then my form will get reset.
Please let me know how will i code this scenario.
Thanks,
Ashish
With due respect, this question is rather broad and you would likely be better served by doing a bit of searching for some base knowledge about the tasks that you are looking to perform.
I would suggest that you begin by going to your favorite search engine and querying for:
HTML Forms
Insert data into a database
ASP.NET Tutorials
Once you have a grasp of the basic technologies that you're using, you should find that it is far easier to accomplish your task. If, by chance, you run into any specific problems or issues, then this would be a great place to ask questions related to them. Best of luck.
asp.net and databases
http://www.asp101.com/samples/db_add.asp
resetting the forms
http://www.java2s.com/Code/ASP/Asp-Control/Resettheform.htm
you should try using google first. these examples came up on top for simple queries like
asp.net databases
and
asp.net reset forms
that said you have not really provided enough information to garner a useful answer.
what database are you using, what version of asp.net (are you even using it, or did you click the tag by accident - you
dont mention it in your post), what platform - specifically?

Resources