Irfan Y
Irfan Y

Reputation: 1310

Table relation and query Entity Framework

Questions:

  1. Should I have to add relation between Mobile Ad and Mobile ? (Mobile entity should not be deleted on deletion of MobileAd and there should not be repeated rows in Mobile table )

  2. Should I have to add relation of AdsLocation with City and PopularPlace ?

  3. Write a query to get ads on the basis of companyName (Mobile table) and should retrieve userName, title, price, companyName, modelName and multiple locations with cityName and popularPlaceName (in short retrieve a column from each table :) Method syntax should be preferred.

enter image description here

Upvotes: 0

Views: 64

Answers (1)

Parth Shah
Parth Shah

Reputation: 2140

1) Yes you should create a relation between mobile and mobile ad because mobile ad is referencing mobile id.

2) Yes you should create a relation between AdsLocation and City because AdsLocation is referencing city id.

3) Until the relation in part 1 is not formed, this query will not be possible. However, while trying to write the LINQ Query for this question, I realized there are some design issues with your database. For example, can the same Ad be posted by different companies? At the moment your design allows it. Your design also allows any user to post the ad for any company. In real world, only marketing team of company X should be able to create ads for company X. I think you should spend some more time reviewing this design!

Upvotes: 3

Related Questions