4

I'm playing around with EF, trying to get my bearings. Right now I'm writing a blackjack game for a website. The problem is that my whenever I pull a GameState from the database, the playerHand, dealerHand, theDeck, and dealerHidden properties are null.

public class GameState
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int gameSession { get; set; }
    public int playerScore { get; set; }
    public int dealerScore { get; set; }
    public Deck theDeck { get; set; }
    public List<Cards> playerHand { get; set; }
    public List<Cards> dealerHand { get; set; }
    public Cards dealerHidden { get; set; }
    public bool gameOver { get; set; }
}

public class Cards
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int cardId { get; set; }
    public string cardName { get; set; }
    public int cardValue { get; set; }
}

public class GameStateContext : DbContext
{
    public GameStateContext() : base("MyContext")
    {
    }
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<GameState>().HasRequired(e => e.theDeck);
        modelBuilder.Entity<GameState>().HasRequired(e => e.dealerHand).WithMany().WillCascadeOnDelete(false);
        modelBuilder.Entity<GameState>().HasRequired(e => e.playerHand).WithMany().WillCascadeOnDelete(false);
        modelBuilder.Entity<GameState>().HasOptional(e => e.dealerHidden);
        modelBuilder.Entity<Deck>().HasRequired(e => e.cards).WithMany().WillCascadeOnDelete(false);
        base.OnModelCreating(modelBuilder);
    }

    public DbSet<GameState> GameStates { get; set; }
    public DbSet<Deck> Decks { get; set; }
    public DbSet<Card> Cards { get; set; }
}

The cards and deck table are populated. Where am I going wrong?


How to print the contents of a two-dimensional array of characters?

I'm trying to print an array of characters in C but i can't print everything. I want to print : b1 b2 My code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
  char def[3][10];     //define a multidimensional array of characters 
  strcpy(def[0],"b1"); //insert "b1" at first line
  strcpy(def[1],"b2"); //insert "b2" at first line
  printf("%s",def);    //print everything?
}

The above code prints just b1. I already tried :

printf("%s",def[0]);
printf("%s",def[1]);

But i have error "invalid use of array with unspecified bounds"

4

1 に答える 1

1

ナビゲーションプロパティ(playerHand、dealerHand、theDeck、dealerHidden lazy)を仮想プロパティにしてロード可能にするか、GameStateをクエリするときに熱心にロードする必要があると思います。

myDBContext.GameStates.Include("playerHand").Include("dealerHand").Include("theDeck").Include("dealerHidden").where(...);

エンティティフレームワークが関連オブジェクトをどのように処理するかについての適切な説明は次のとおりです。

http://msdn.microsoft.com/en-us/data/jj574232.aspx

于 2012-12-15T20:52:18.290 に答える