exam questions

Exam AZ-203 All Questions

View all questions & answers for the AZ-203 exam

Exam AZ-203 topic 3 question 2 discussion

Actual exam question from Microsoft's AZ-203
Question #: 2
Topic #: 3
[All AZ-203 Questions]

HOTSPOT -
You are working for a company that designs mobile applications. They maintain a server where player records are assigned to their different games. The tracking system is new and in development.
The application uses Entity Framework to connect to an Azure Database. The database holds a Player table and Game table.
When adding a player, the code should insert a new player record, and add a relationship between an existing game record and the new player record.
The application will call CreatePlayerWithGame with the correct gameIdand the playerId to start the process. (Line numbers are included for reference only.)

For each of the following statements, select Yes if the statement is true. Otherwise, select No.
NOTE: Each correct selection is worth one point.
Hot Area:

Show Suggested Answer Hide Answer
Suggested Answer: Explanation
Box 1: Yes -

Box 2: No -

Box 3: Yes -

Box 4: No -
Many-to-many relationships without an entity class to represent the join table are not yet supported. However, you can represent a many-to-many relationship by including an entity class for the join table and mapping two separate one-to-many relationships. protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<PostTag>()
.HasKey(t => new { t.PostId, t.TagId });
modelBuilder.Entity<PostTag>()
.HasOne(pt => pt.Post)
.WithMany(p => p.PostTags)
.HasForeignKey(pt => pt.PostId);
modelBuilder.Entity<PostTag>()
.HasOne(pt => pt.Tag)
.WithMany(t => t.PostTags)
.HasForeignKey(pt => pt.TagId);
}
}

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
brajen
Highly Voted 4 years, 11 months ago
Discussion is getting confuse..
upvoted 27 times
...
gssicftohbcrcsgtjg
Highly Voted 5 years, 3 months ago
options https://www.examtopics.com/assets/media/exam-media/02521/0004800001.jpg
upvoted 23 times
...
yllkabaci
Most Recent 1 year, 2 months ago
I have writed the code and here is my answer: 1. No becouse we get an exception SqlException: Cannot insert explicit value for identity column in table 'Player' when IDENTITY_INSERT is set to OFF. Indeed you can't set dhe Id, it will be autoincremented (if you don't set identity_insert to off) 2. No because : - player will not be inserted - if we don't specify PlayerId we will get an error on Game like below: SqlException: Cannot insert explicit value for identity column in table 'Games' when IDENTITY_INSERT is set to OFF. 3. No because the code will not insert any row. 4. Yes, many-to-may relationship will be created.
upvoted 1 times
...
altafpatel1984
3 years, 6 months ago
Entity class and HasMany/WithMany shows many to many is supported, but since code inserts player with only one gameid, it seems many to one only.
upvoted 1 times
...
altafpatel1984
3 years, 6 months ago
Y N N (if GameIs is not type mistake) Y (since Player class has List<Game> property and Game class has List<Player> property, and since it also mentioned as HasMany-WithMany so this is many to many relationship.) Many to many since
upvoted 1 times
altafpatel1984
3 years, 6 months ago
I guess GameIs is typo mistake other wise code will not compile and hence will not at all resulting into all answers as No !! So answer would be Y N Y Y
upvoted 1 times
altafpatel1984
3 years, 6 months ago
My previous answer slightly not correct. Here is correct: Y N N Y
upvoted 1 times
...
...
...
dancsita
4 years, 4 months ago
Y N Y N is the correct answer 1. Y - the player record will be inserted successfully by the AddPlayer 2 N - there's no code where a new gameid would be added 3 Y - when referring to the game id, a new object is created, it will empty 4. N - many-many relationship has a different syntax (HasMany, WIthMany)
upvoted 2 times
altafpatel1984
3 years, 6 months ago
HasMany/WithMany is already there in code.
upvoted 1 times
...
...
cbn
4 years, 4 months ago
Wonder why a complete programming question coming under Azure!
upvoted 2 times
minsma
4 years, 3 months ago
because it is a Developer certificate..
upvoted 2 times
...
...
tmfahim
4 years, 5 months ago
If the text for this question is correct, then everything should be "No". There is no property "GameId" in the Game class, rather it is "GameIs". So the code will definitely not run.
upvoted 1 times
Juanlu
4 years, 3 months ago
Agree: 1. YES 2. NO 3. YES. GameId is not a property of Games, so GetGame(id) doesn’t work. But if it a typo the answer is NO. 4. NO.
upvoted 3 times
...
...
dylansun
4 years, 5 months ago
I think the answer should be Yes, No, No, No
upvoted 1 times
...
NajamKhan
4 years, 7 months ago
guys, All are YES. The correct answer, tested on EF console application.
upvoted 6 times
...
swiftfoxmark2
4 years, 7 months ago
I copied this code to an Entity Framework console application and ran it. The answers I got were all "Yes" in this case. If using Entity Framwork Core, however, the last answer would be "No".
upvoted 5 times
...
Mike204
4 years, 9 months ago
Answers do not matter if you cannot view the questions.
upvoted 1 times
lamamo8656
4 years, 9 months ago
https://www.examtopics.com/assets/media/exam-media/02521/0004800001.jpg
upvoted 1 times
...
...
SagarShete
4 years, 9 months ago
According to me Answer is Yes - Code will successfully insert the player record No - There is no bug in the code and no additional copy will be created. No - No getting why will it be wrong game id when i am already passing the gameid in function. AddPlayer(playerId, GetGame(gameId)) -- Which will get the exact associated game id. No - Yes, Entity framework supports many to many but it is in this context. Is it required. According to me it's not required. The problem statement states " When adding a player, the code should insert a new player record, and add a relationship between an existing game record and the new player record."
upvoted 1 times
...
quokka
4 years, 9 months ago
It's Y N N N. The last N for Many-to-Many relationship should be like the example in https://docs.microsoft.com/en-us/ef/core/modeling/relationships?tabs=fluent-api%2Cfluent-api-simple-key%2Csimple-key#many-to-many
upvoted 2 times
quokka
4 years, 9 months ago
I meant Y N N Y. Found a M-M relationship example from another MS doc https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-a-more-complex-data-model-for-an-asp-net-mvc-application#add-code-to-database-context
upvoted 7 times
...
...
Dishak
4 years, 9 months ago
Answer is Yes No No Yes
upvoted 6 times
...
Mr2302682
4 years, 10 months ago
The Answer is: 1-Yes - why shouldn't it be inserted? 2-No - You read an existing game and put it into the player intstance. This is just a reference! 3-No- See the answer before. It is just a reference. The player played a game that aleready existed. 4-Yes - But here I'm not sure.
upvoted 8 times
...
Kainite
4 years, 10 months ago
This is confusing and I don't see any concrete justification so this is what I think is the correct Answer: Yes - this inserts a player record into players, not a new player because to get the player context this player need to exist No - it's not inserting new games and the id it gets is from one already exist on the players context Yes - return db.games.FirstofDefault (x=> x.GameId==gameId) i do believe it will get any other game not the one in context because is get the first game ID of the player in a context that may not be the correct one. Yes - The class Player has public virtual List<Games> and the class Game has public virtual List<Players> so this means that need to have a M-M relationship
upvoted 1 times
Mr2302682
4 years, 10 months ago
why do you think you get the wrong gameid? The GameID is unique!
upvoted 3 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...