How To Layout Tables And Relationships For MVC Project

Nov 22, 2010

So I am working on an MVC project to put to work the studying I have been doing. I am wrestling with the concept of Database Table relationships and foreign keys. I am working on a simple ecommerce site (displays products, shopping cart, user accounts..etc).

I have the following tables to start out with:

1) Products

2) Categories

I setup the Products and Categories tables to have a ProductId and CategoryId respectively. In my MySQL db, I created a FK on the Products Table to relate to the CategoryId field on the Categories table (I am not sure this was correct to begin).

My expectations for the way the database would handle the table relationship: I didn't want the DB to do anything with the products table if I deleted a category out of the Categories table, or vise versa. The only thing would be that the category field in a Product would be blank (or default) if their category was removed.

Finally, do I have to do anything in my entity classes such as in the Products class, add the ProductId to the Category.ProductId?

Eventually, when I Orders and Users to the project, I can see a relationship where each user -> many orders -> each order has many products -> and each product is in one category.

But I am having a hard time understanding how or if I should be setting up a Foreign key relationship in the two current tables of Products and Categories and if so how to setup my entity class in relation to that FK.

View 1 Replies


Similar Messages:

Relationships And Displaying Data From Tables In ASP

Jan 8, 2010

Does anyone no of any good resources regarding many-to-many relationships? More specifically on displaying data from many-to-many tables in ASP. Struggling to find anything but I may just be over complicating things!

View 18 Replies

WebMatrix :: How To Define Relationships Between The Tables

Jul 14, 2010

I have been experimenting with WebMatrix, specifically the ability to connect to and use SQL CE data.

My question is:

When I am creating a new SQL Compact database with several tables, how do I define relationships between the tables?

The "Relationships" button in WebMatrix is always greyed out. Is that because it is still in Beta? Or am I missing something?

View 5 Replies

ADO.NET :: LINQ To Entity Error Seeing Relationships Across Multiple Tables?

Jan 24, 2011

I'm a newbie to this so bear with me. From what I've read online LINQ to Entity should see the relationships without having to specify the joins between multiple tables. I have a relationship that goes across 4 tables Employee, EmployeeDepartmentLink, EmployeeProjectLink, and Project. The idea is an employee can be in multiple departments and work on multiple projects with it being specified which department the employee is in for that project.

This is a C# MVC3 program connecting to a SQL database using VS 2010 Express.

I have no problem with running this query to find employees on a project:

[Code]....

Tring to do the reverse, finding projects that an employee worked on results in an error:

[Code]....

Error message: The specified type member 'EmployeeDepartmentLinks' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported. So I have 2 questions,

1) Why would it work in one direction and not the other? I've played around with it for a couple days with the same results.

2) Does it matter that my primary key and foreign keys are not named the same since all the relationships are connected in SQL? Ex: in Employee (EmployeePK)--(EmployeeFK) in EmployeeDepartmentLink Trying different stuff in LINQPad I was able to get the 2nd query to work if I specified all the joins which I thought was not neccesary with LINQ to Entity. I converted an SQL query that I made on the server into a LINQ query below which works.

View 5 Replies

DataSource Controls :: Sql Table Relationships / To Create A Dependency Between The 2 Tables

May 3, 2010

I have a table that contains item data. If the item is a particular type further information exists to describe the item. The additional information isn't that heavy however the number of records in relation to the main file will be quite small (less than
5%).

So I have 2 scenarios:1) Put the additional data in the main table and take tha hit on storage

2) Create an additional table and link the 2 together

If we were talking huge amounts of data I can understand that 2) would be the obvious choice but given the simplicity should 1) be a consideration?

If 2) is the answer - is it possible to create a dependency between the 2 tables when the item is 'that' particular type. In other words wnsure the addition data is populated for the required items and not others.

View 1 Replies

How To Display HTML Layout Without Tables

Jan 19, 2010

What is the easiest why to display two buttons, one underneath the other, without using a table?

View 3 Replies

Web Forms :: Use Div Tag For Site Layout Instead Of Tables

Feb 22, 2010

I'm re-educating myself to use div tags for site layout instead of tables. In my web application, I have a master page and several content pages. For the masterpage, I wrote this for a simple header:

[Code]....

View 3 Replies

Saving Div Layout / Tables With Content Via C# Or JavaScript?

Mar 16, 2011

I have some JavaScript that on button click takes a the text from the textarea and places it into a div.

What I would like to do preferably via C# is save that content (somehow) to a textdoc maybe? or straight into the database (unsure as it could contain alot). So unfimilar with JavaScript hence my preference for C but if JavaScript could do the job it would be nice to have the client side run the script.

Atm all I want to do is save the divs somehow then later I will learn how to retrieve them.

The JavaScript I have atm for creating the div:

<script type="text/javascript">
$(function () {
$('button').click(function () {
var x = $('textarea').val();
$('textarea').val('');
$('#test1').append('<div id="test">' + x + '</div>');
return false;
});
});
</script>

which outputs:

<div id="test1">
<div id="test">Write Something....</div>
<div id="test">Write Something....</div>
</div>

As you can see there can be many of the same type but if I could just save that data then i could find a way to load it later!

View 2 Replies

Vb.net - Keeping Tables Cached On Server In Project?

Mar 7, 2010

I have an ASP.NET project which is a front-end to a database. In addition to the large tables, the DB contains a few small tables to normalize the larger tables with common values. I have a VB.NET project which loads the smaller tables into memory, using "Shared" (i.e., "static" in C#) member variables, and uses them. I have a call to load the tables in Global.asax - Application_Start. This works for a while. That is, Application_Start runs when I first run my project, loads the cached values, and will correctly keep them in memory for a while.

What I'm seeing (when running my project via Visual Studio 2008 Debugger, hosted locally) is:

A) The Application_Start code will run more than once. Not in a row, but after the user has navigated to some other pages, I'll see (my breakpoint in) another call to initialize the cache, coming form Application_Start. Is it expected?

B) The "Shared" variable that was set to True when the cache was initialized is now False again (which should only happen when the class is first loaded). Similarly, all the data that was chached is no longer present. That is, it looks like VB is unloading all the Shared members. Is this expected?

If these are the expected behaviors, is there a way to do what I want? The code is in a module that is also used by other (non-ASP.NET) projects, and seems to work correctly for them. I'd rather not have to duplicate this functionality for something specific to ASP.NET, but would like to know what my options are.

View 1 Replies

MVC :: What Is The Best Approach To One To Many Relationships

Aug 5, 2010

What is the best approach to one to many relationships?

This is my scenario:

I have a simple one to many relation:

Customer
CustomerID
Name
tel
CustomerNotes
Id
Note
customerID

I want to have a DETAIL view of customers and CREATE view for CustomerNotes all in the same page.

I create CustomerController and the different views and its respective actions for edit, create, delete, etc.

I also create a CustomerNotesController and the views and actions like before, but I made the views PARTIALS

I put a RENDERPARTIAL for the CustomerNotes create view in the Details view from Customer.

When I run the app, the page is render as expected: It shows the detail info of the customer and bellow the create form for the notes. However, when I click SAVE, nothing happens. I put a breakpoint in the notes controller and never get hit.

I also try with RenderAction and don't work at all.

View 4 Replies

C# - Add Relationships To The Aspnetdb Database In MVC?

Feb 1, 2010

I'm having a hard time wrapping my head around how to use the Memberships in MVC. I know there is the built in ASPNETDB database which has all the basic tables for users and such. But what if I wanted to add a relationship between one of my custom tables and this built in user table?

If I had a database table that contained blog comments, we'll call it Comment. And each Comment had a userID associated with it could I do something like?

User.Comments.Add(someCommentObj)

View 3 Replies

Create Classes To Represent One To Many Relationships In C#?

Jun 20, 2010

how to create C# classes to represent one to many relationships in C#. I have a Customer and an Address table in my database. I also have a Customer class in my C# solution but how do I introduce the multiple address element? Do I have a separate Address class? Do I create a subclass in the Customer class or create a method in Customer called GetAddresses of type List which contains all of the relevant logic? In my code I need to be able to return a customer with all associated addresses and I just cannot picture the best way to achieve this using OOP.

View 9 Replies

Deleting Entity With Child Relationships

Apr 10, 2010

EF is so frustrating. I can't seem to be able to get my head around what I need to do so I can delete an object. I seem to be able to remove the object but not the related child objects. Can anyone tell me what is the rule of thumb when you want to delete all related child objects of a given object? I've tried loading all related objects like this:

Entry entry = ModelContext.GetObjectByKey(new EntityKey("ModelContainer.EntrySet", "Id", id)) as Entry;
entry.ChildEnteries.Load();
if (entry != null)
{
ModelContext.DeleteObject(entry);
ModelContext.SaveChanges();
}

I get errors related to the relationships: A relationship is being added or deleted from an AssociationSet 'EntryEntry'. With cardinality constraints, a corresponding 'Entry1' must also be added or deleted. Why can't I just load the object using modelcontext.GetObjectByKey and remove it along with its child objects? My other question is can I delete an object using Entity command like so? DELETE e from objectset as e where e.id = 1 I've tried few variations and all of them throw exceptions.

View 1 Replies

How To Describe The Relationships Between Proxies And Bases

Mar 16, 2011

this is a bit of a nomenclature question:what is the correct way to describe the relationships between these classes (the thing that throws me off is the use of generic types here):

[Code]....

View 1 Replies

MVC :: Data Filter Using Dataloadoptions Across Relationships?

May 27, 2010

Using dataloadoptions i have tried the following example

[Code]....

Now i need to ask how can i display Category ID and Category Name of the productID (i am supposing that One product can be in at most one category) by extending the above example Regards.

View 1 Replies

C# - Managing Many To Many Relationships In Asp.net Wizard Control?

May 27, 2010

Say I have this entity with a lot of attributes. In the input form I have decided to implement a wizard control so I can collect information about this entity in several steps. The problem is that I need to collect information that has been modeled has many to many relationships. I am planning to use a telerik gridview to manage this (add/edit/delete), the problem is where do I store that data since the entity in a insert form is not created on the database yet. OK so I can store all that info in temporary lists residing in the viewstate, waiting for the final submit where I dump all that in the DB, but one of the steps I am collecting files...now storing files in the viewstate is out of the question, same as as storing them in the session...I have been thinking of implementing in a way that the user has to submit some info first (say first 3 steps), commit the data to the database creating the parent entity and then start inserting all the childs entities...but this will get weird as it's confusing since on the first steps you not saving the data to the DB and on the next ones you are commiting directly...

View 1 Replies

How To Get Code Coverage Working On A VS 2010 Project/Cannot Initialize The Project 'Project Name'

May 23, 2010

When I turn on Code Coverage in my test settings, on a project that references the Unity DI container I get the following error:

Cannot initialize the ASP.NET project'{Project Name}'.

The event log specifies the following reason:

Could not load file or assembly 'Microsoft.Practices.Unity, Version=2.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Strong name signature could not be verified.

View 2 Replies

FluentNHibernate ClassMaps / How To Code Relationships Period

Apr 21, 2010

Just a quick question for those more familiar with FluentNHibernate. I've read the quick start things, and the docs on their site, but am still a tad off. Are the following maps correct, in terms of the HasOne / HasMany relationships? If not, correct them, and give me reasons, so I better understand.

C sharp Code:

[code]....

These will eventually go into a convention file, but for now, I just need to know how to code relationships period.

View 4 Replies

SQL Server :: How To Duplicate A Record From A Table And All It's Relationships

Sep 16, 2010

I'm using SQL Server 2005 in a project, and i need to duplicate a record from a table and all it's relationships.

View 9 Replies

ADO.NET :: Entity Framework - Query Based On Relationships?

Oct 27, 2010

I have the following related tables:

Users
Id
Username
Email
Password
UserStatuses
Id
Name
Users_UserStatus
Id
User (FK - Users: Id)
Status (FK - UserStatuses: Id)
StatusDate

As you can see, UserStatuses is a reference table with various statuses. Users_UserStatus is a join table between Users and UserStatuses. Using Entity Framework, how can I do a conditional to check if the latest StatusDate is "Pending"? As of now, I have the following:

[Code]....

View 1 Replies

Render A Group Of Object Relationships Like Visio?

Apr 8, 2010

Does anyone know of a control or a way to render a group of object relationships like visio? Right now I just have them sitting inside nested divs, but it's not as slick as everything being connected with lines in a flow

View 1 Replies

Perform Relationships In Entity Framework 4 Code-First CTP 5 ?

Jan 19, 2011

I would like to have a short example on how do you actually perform relationships in Entity Framework 4 Code-First CTP 5 ?

Would love an example for these kind of relations :

* one-to-many
* many-to-many

View 1 Replies

DataSource Controls :: Restrict Relationships In Sql Server 2005?

Jun 15, 2010

i have two tables with PKs assigned to them. i wanna build a one to five relationship between them. how can i do this?

View 2 Replies

MVC :: UML Class Diagram For Application Include All The Controllers And Views And Their Relationships?

Mar 16, 2011

I would like to ask a plain and simple question about the Model-View-Controller architecture - should the UML Class diagram for my application include all the controllers and views and their relationships, or should it just include my model classes, i.e. the entities that are the heart of the application, you know - like in an ordinary application - i.e. User, Administrator, Student, Teacher, Course, Grade etc...?

View 1 Replies

C# - In LINQtoSQL, How To Update Child Relationships By Editing The Parent Model

Oct 5, 2010

This is my first attempt at updating a database using LINQtoSQL. At least, it's my first if you don't count the tutorials I've followed. Unfortunately, The tutorials that I have found don't offer much more than updating a single table. I'm attempting to update a DB Model that's a bit more complex.

I have a Stream table:

[Code]....

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved