Jump to content
  • 0

Load Database


Mimus

Question

sorry for my english, i use a translator

 

Hello, I have created a database to give with the migration system, I manage to use it ... it is linked to the character, the problem I encounter is that when the person loads the data is not not charge, on the other hand if I add an addition all the data is charged. I probably forgot a piece of code somewhere but I can't find it or again ..

 

In Short:

- DB Works

- In load Player, not load my table

- If i add new raw in table, add and load in Player all data for player.

it's just the loading of the player that is problematic. and that does not load the link table

 

I added in the Querry:

Spoiler

...

.Include(p => p.Bank)
.Include(p => p.Friends)
.ThenInclude(p => p.Target)
.Include(p => p.Hotbar)
.Include(p => p.Quests)
.Include(p => p.Variables)
.Include(p => p.Items)
.Include(p => p.Spells)
.Include(p => p.MailBoxs)
.ThenInclude(p => p.Sender)

 

I added in the modelBuilder (PlayerContext):

Spoiler

modelBuilder.Entity<Player>().HasMany(b => b.MailBoxs).WithOne(p => p.Player);

 

and here is the class i use:

Spoiler

public MailBox()
{
}

public MailBox(Player sender, Player to, string title, string msg)
{
	Sender = sender;
	Player = to;
	Title = title;
	Message = msg;
}

[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; private set; }

[JsonProperty(nameof(Player))]
private Guid JsonPlayerId => Player?.Id ?? Guid.Empty;

[JsonProperty(nameof(Sender))]
private Guid JsonTargetId => Sender?.Id ?? Guid.Empty;

[JsonIgnore]
public virtual Player Player { get; private set; }
		
[JsonIgnore]
public virtual Player Sender { get; private set; }

public string Title { get; private set; }

public string Message { get; private set; }

 

thank you in advance for your help

 

 

EDIT 06/04/2020

I succeeded, but I don't know if it's the cleanest system compared to the engine ...

I call this function in "public static Player Load([CanBeNull] Player player)"

Spoiler

public static void GetMails(PlayerContext context, Player player)
{
	var mail = context.Player_MailBox.Where(p => player.Id == p.Player.Id).Include(p => p.Sender).DefaultIfEmpty().ToList();
	player.MailBoxs = mail;
}

 

 

Edited by Mimus
Add solution...
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

that's what I did, if I add a line to the model builder or even to the query it is because the data was not automatically loaded ... by the way I think that I little withdraw them seen I make a call to load data manually so good ...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...