Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm writing an exam project. A summary of events is as follows; manager opens an exam and schools for the exam consists of a chairman and two members will establish a commission. Committee members will be selected from the staff table.
In relational database design, you need to use primary keys and foreign keys to relate tables to each other. A primary key is a unique identifier for a table and foreign keys are references to primary keys in other tables. Then you perform joins on your tables to get back the related data you want.
For your case, you need some sort of relation between the two tables that you listed and then you can create a many to one relationship. A many to one relationship consists of many records in one table relating to one record in another table.
For example:
tblCommittee
CommitteeId
Name
DateCreated
Person1Id
Person2Id
tblPerson
PersonId
Name
Sample data:
Person
PersonId Name
1 Billy
2 Joe
3 Bob
4 Jeff
Committee
CommitteeId Name DateCreated Person1Id Person2Id
1 Committee one 1/7/2014 1 2
2 Committee two 12/3/2013 4 3
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I am creating a web app using ef core, and I have three entites, Student, Teacher, and Project. Now each of these tables needs to have multiple Links (Id & Url columns here) that point somewhere on the web. What is the best way to design this relation.
I've thought adding a StudentId, TeacherId, and ProjectId nullable column to the Links table. I've thought of creating a Links table for each entity. I've also thought of using a discriminator column, but still, it doesn't feel right.
How do I properly design this?
Note: The Student and Teacher table have a one to one relation with a user table, so I could just put the foreign key there, but the Project table is unrelated to these.
Based on the comments the link, you have a set of links for some or each of your entities in question.
But these are attributes, even a link array is an attribute of those entities, as a link is not an entity on its own. Unfortunately, 1NF requires each attribute to have a unique value. But let's be serious: is this an unbreakable constraint? Of course not. Some RDBMS do have array columns. SQL Server does not. But it has XML and JSON column types. EF has some other tools to provide the same.
Actually it depends on what do you want to do with those links: are they somehow processed with SQL or not. If only the upper tiers are handling them - and I suppose they are processed on the visualization tier - from the database point of view the link array is a single attribute.
If those links are passing trough your business logic, and they are only used during rendering, you can simply store them as comma-separated lists, or JSONS text in a nvarchar with a string property counterpart in the EF entity class, and split/parse them only on the visualization tier. That would make the less concentrated effort.
If your business logic needs them separately, EF does have support for complex types. You can still store your arrays as JSON text in a nvarchar column and serialize-deserialize them transparently. Check here: https://www.codeproject.com/Articles/1166099/Entity-Framework-Storing-complex-properties-as-JSO even better solution here: https://entityframework.net/knowledge-base/14779740/can-i-embed-an-object-in-an-ef-entity--serialize-on-save--deserialize-on-access--
SPARSE is still there of course, if applicable.
You can use below three mapping tables. Which are maintain your many to many relationship.
Like: 4 to 5 students working on same link.
2 teachers handling same link.
create table student_link_mapping(slmid int identity(1,1), studentid int not null, linkid int not null)
create table teacher_link_mapping(tlmid int identity(1,1), teacherid int not null, linkid int not null)
create table project_link_mapping(plmid int identity(1,1), projectid int not null, linkid int not null)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
We have a cartesian product and currently we are storing in a single table and this table is growing drastically and user can perform update and read operations on these entities and we have a soft delete when user deletes the record.
And now we are getting hit by performance issues for read and update operations.
Basically this cartesian product holds permissions for different roles and categories.
Wanted to know if anyone came across the similar situation and understand the best practices to store the cartesian product.
I was also thinking to split this into N table and then write and update individually for each type and then while reading perform a join.
So what are the best practices to store a cartesian product.
Cartesian product simply mean product of two tables, otherwise its just a table and not a Cartesian product, so of course it should be split and whenever needed, the Cartesian product can be produced from these 2 tables.
Imagine that Table1 and Table2 each has 1000 records, a Cartesian product of these 2, will have 1000000 records, the records that can simply be produced from these 2000 records.
And of course using conditions, you may produce only a portion of the Cartesian product that you need and not all of it.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have the entities User and BlockedUser. A User has many BlockedUsers. BlockedUsers is a list of Users that are blocked by the User. How can I implemented these classes using Code First? After the database is created. There is no trace of the BlockedUser in the User table.
public class User : IdentityUse
{
public List<User> BlockedUser;
}
I just ef database first so I first created tables like below.you have many to many relationship.
create table User
(
ID int primary key,
Name nvarchar(100),
)
create table BlockedUsers
(
UserID int,
BlockUserID int,
primary key( UserID, BlockUserID),
foreign key ( UserID) references User(ID),
foreign key ( BlockUserID) references User(ID),
)
YOU CAN create table then create model from that
There won't be a trace of BlockedUser in the User table. It will create a BlockedUser table which will have a foreign key back to the User table. So you might have five rows in the BlockedUser table eventually, all referring back to User with ID 1. When you navigate to BlockedUsers via the List property on User, EF will load the BlockedUsers for you.
You should create the List property with the virtual keyword if you want lazy-loading of BlockedUsers.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I write my project and I will give to user to add his store to my system and then user will can to add shopItem to his store.
My question is:
Maybe already exist shop database for Category-Subcategory.
I mean - When user will add for example boots - he need choose
Category Clothes -> then choose Subcategory Shoes.
So i need database with all category-subcategory for MS SQL - or other database (maximum I will write script for transfer data to MS SQL)
Thank you.
Regards,
David.
You are talking about a hierarchical relationship. Typically you would have a Category database which has a primary key (say, CategoryID). If a subcategory can only belong to single category, then you would have another field in your Category table (maybe called ParentCategoryID). For root-level categories, this field would be NULL. For a subcategory, ParentCategoryID would contain the CategoryID of whatever category is the parent (pretty logical).
If a subcategory can exist under multiple categories, then you need a mapping table that contains the CategoryID and ParentCategory ID.
If you need a subcategory also to be allowed to be a root category, then your mapping table has to take this into account (maybe by allowing NULLs in the ParentCategoryID table)
MSDN has a tutorial on hierarchical data structures here: https://msdn.microsoft.com/en-us/library/bb677213.aspx
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i have a grid view shopping cart in my application. the datasource of gridview is session as datatable.. i have no problem in shopping cart. my cart is perfectly the way i want it.. now my problem is that on PLACEORDER button click i want to export this gridview details into database like
-----------------------------------------------------------------------
Orderid | Orderdate | products | amount | username
-----------------------------------------------------------------------
xxx | datetime.now |all products in cart | total amount| currentuser
-----------------------------------------------------------------------
single row in the order table should contain all the details about the order that a user places
Now my question is it possible to do it ? if yes how ? please explain. i m short of time .. thanks in advance
You need a second table, that would have 3 columns:
1. Your primary key for the table
2. OrderId (a foreign key to your order table)
3. The product or the productId.
Then you can select all the products with a given OrderId to see what was ordered on that order. This also allows you to count products sold and a bunch of other reporting if needed.
The wrong way to do it would be to store it in the same table as a long string. This allows no reporting, forces you to parse it in your code, ruins all scalability... It is a bad solution don't do it.