Click here to Skip to main content
15,569,644 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello
I am on my first EF6 project and I have couple of questions

Project outlines
Property (Building) have Rooms
A Room have list of criteria or rating
Each criteria own a set of values
i.e.
Property (Building) A have
Room 1
Each room have bunch of values
Value a 0-1
Value B 2-5 ... etc.

Room 2
Each room have bunch of values
Value a 1-3
Value B 0-5 ... etc.


Property (Building) B have
Room 1
Each room have bunch of values
Value a 0-1
Value B 4-9
Value c 0-1 ... etc.

Room 2
Each room have bunch of values
Value a 1-3
Value B 0-4 ... etc.
...


Therefore, by nature a property (Building) have a list of rooms, each room have its own values
Therefore, the database design is
Property 1...N Rooms
Rooms 1...N Values

These values can be modified on desire

I am using EF6 to handle the DB, and Caliburn.Micro BindableCollection
Pulling the data from the DB using DbSet
Now, the dilemma is to save the Rooms and its values without duplication, I tried updating the dbSet using the loops but that only caused data duplication.
I could not find a way to empty the DbSet from its data without reverting to spaghetti code, which I’m trying to avoid

My Question is How to save the data to the DB without
1- Duplication
2- Spaghetti and very ugly code
3- Dropping the frameworks I am using

thanks in advance

What I have tried:

Empty DBContext and its DbSet
Convert ICollection to DbSet
Saved successfully but with Duplicated data
Posted
Updated 19-May-19 13:46pm

1 solution

Right
first of all sorry for the rough English, I am a mess right now
the solution is as follows:

Loop through the existing Main categories (Property(Building))
for Property.Count
Property[i].Rooms = inProperty[i].Rooms

So on and so forth for the other nested lists

PropertyDBContext.SaveChanges();

if you guys have a better solution i will always welcome c&c
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900