Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include doesn't work sometimes #4284

Closed
Erwandebenaze opened this issue Jan 12, 2016 · 10 comments
Closed

Include doesn't work sometimes #4284

Erwandebenaze opened this issue Jan 12, 2016 · 10 comments

Comments

@Erwandebenaze
Copy link

Hi !
(Sorry for my english)
For my student project I have a Database with lots of tables but only 3 are concerned here.

First one is in TPH :

    public abstract class Event
    {
        public long EventId { get; set; }
        public string EventType { get; set; }
        public DateTime BegginningDate { get; set; }
        public DateTime EndingDate { get; set; }
        public bool Done { get; set; }
        public Island Island { get; set; }

        abstract public void Accept(EventManager visitor);
    }

With the second one who implement Event

    public class UnitEvent : Event
    {
        public Unit Unit { get; set; }
        public override void Accept(EventManager em) => em.Resolve(this);

    }

The table Event take others class like UnitEvent (ArmyEvent, BuildingEvent, TechnoEvent etc...)

The TPH works and all data are binded.

This is the class Unit :

    public class Unit
    {
        public int UnitId { get; set; }

        public string Name { get; set;}

        public UnitName UnitName { get; set; }

        public UnitDamageType UnitDamageType { get; set; }

        public UnitType UnitType { get; set; }

        public UnitStatistics UnitStatistics { get; set; }

        public Ressource UnitCost { get; set; }

        public int Duration { get; set; }
    }

The problem is in the line :

UnitEvent unitEvent = _context.UnitEvents.Include(a=>a.Unit).Where( e => e.EventId == ue.EventId ).Single();

It throw IndexOutOfRangeException
Withtout the Include(a=>a.Unit), the query works.
An other query, juste before on the same table I have

 List<ArmyEvent> eventsWhereTarget = _context.ArmyEvents.Include(u => u.Army).ThenInclude( j => j.Regiments).Where(e => e.Done == false && e.EndingDate > DateTime.Now && e.Destination.IslandId == islandId).ToList();

This is my project.json

{
  "webroot": "wwwroot",
  "userSecretsId": "Skylord",
  "version": "1.0.0-*",

    "dependencies": {
        "EntityFramework.Commands": "7.0.0-rc1-final",
        "EntityFramework.Core": "7.0.0-rc1-final",
        "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
        "EntityFramework.Relational": "7.0.0-rc1-final",
        "Microsoft.AspNet.Diagnostics": "1.0.0-rc1-final",
        "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc1-final",
        "Microsoft.AspNet.Identity": "3.0.0-rc1-final",
        "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final",
        "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
        "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
        "Microsoft.AspNet.Mvc.Razor": "6.0.0-rc1-final",
        "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
        "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
        "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
        "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
        "Microsoft.Dnx.Runtime": "1.0.0-rc1-final",
        "Microsoft.Extensions.Configuration.Abstractions": "1.0.0-rc1-final",
        "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc1-final",
        "Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0-rc1-final",
        "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
        "Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc1-final",
        "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final"
    },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel",
    "ef": "EntityFramework.Commands"
  },

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules",
    "bower_components"
  ],
  "publishExclude": [
    "node_modules",
    "bower_components",
    "**.xproj",
    "**.user",
    "**.vspscc"
  ],
  "scripts": {
    "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
  }
}

Thank for your help.
If needed, my project "Skylord" is on github, branch Event.
Bye !

@rowanmiller
Copy link
Contributor

@smitpatel is this a dupe of an issue you have already fixed?

@rowanmiller
Copy link
Contributor

@smitpatel #3994 was the issue I was thinking this is probably a dupe of

@Erwandebenaze can you provide a link to the source of your project? I couldn't see a Skylord repo on your user profile.

@Erwandebenaze
Copy link
Author

@rowanmiller https://github.com/ITISkyLord/SkyLord.git it's on the branch Events.
Folder Services, EventManger.cs => arround line 193, function public void Resolve( UnitEvent ue )

I have temporaly added a "UnitIdd" on my database to pass throught the problem.
You will find the same bug on public void Resolve( ArmyEvent ae ) and i solved it by the same way (not proper).

To generate the problem (the site is in french :/) :
Click on "Inscription", fill the fields (passwords must have 6 char)
Then the connexion supposed to work. Click on the top nav bar on "Armées" then put a number on the field "Gobelin" the units make 10sec to build for the moment. After 10 sec, click again on "Armées" or refresh the page then the unit is built. With the UnitIdd it works, with the Include in the initial post, it throw IndexOutOfRangeException.

Hope it's clear.
I will right a TestFixture this morning to help you. We are late and i didn't have time to do all TestFixture sorry.

I hope it's not a draft for you..
Thank you for your attention !

PS : You have to update the database with SetupContext : dnx ef database update -c SetupContext

@Erwandebenaze
Copy link
Author

@rowanmiller I reproduct the same thing in a test and it works perfectly...
I pushed it on he same branch

@rowanmiller
Copy link
Contributor

@Erwandebenaze I tried reproducing this... I am able to run the application, and follow the steps down to then put a number on the field "Gobelin" (I assume I am supposed to click the Entrainer les unites button after putting a number in the field?). It doesn't look like this sends any updates to the database and every time I click again on "Armées" or refresh the page it just displays the page with 0 in all the fields again (no error).

@rowanmiller
Copy link
Contributor

BTW I assume I was supposed to uncomment the line that was commented out in Resolve

        public void Resolve( UnitEvent ue )
        {
            // À remettre en place quand on aura la solutions pour Include

            //  /!\ HERE IS THE PROBLEM with Include. /!\
            UnitEvent unitEvent = _context.UnitEvents.Include(a=>a.Unit).ThenInclude( b => b.UnitStatistics ).Where( e => e.EventId == ue.EventId ).First();

            Unit unit = _context.Units.Include( y => y.UnitStatistics ).Where( u => u.UnitId == ue.UnitIdd ).Single();
            ArmyManager am = _allManager.ArmyManager;
            am.AddUnit( unit, 1, ue.Island );
            // TODO : Si plusieurs lignes sont finies en même temps, on peut les cumuler avec ArmyManager.AddUnit

        }

@Erwandebenaze
Copy link
Author

Oh ?
The table dbo.Event is update when you train units. Is it work ?
If yes, you have a ending date and with Generic Controller when you refresh Armées it works.

Try to coment Unit unit = _contre.Units ....

Like that :

            //  /!\ HERE IS THE PROBLEM with Include. /!\
             UnitEvent unitEvent = _context.UnitEvents.Include(a=>a.Unit).ThenInclude( b => b.UnitStatistics ).Where( e => e.EventId == ue.EventId ).First();

          //  Unit unit = _context.Units.Include( y => y.UnitStatistics ).Where( u => u.UnitId == ue.UnitIdd ).Single();
            ArmyManager am = _allManager.ArmyManager;
            am.AddUnit( unitEvent.Unit, 1, ue.Island );

The exception is thrown everytime for me...

@rowanmiller
Copy link
Contributor

On the Armées page, if I click Entrainer les unites then no updates are sent to the database. It posts back to the ArmyController.AddUnit action but it looks like there is an issue with binding as model.UnitAmount is set to 0 and therefore the action sets an error but then redirects to the island view anyway.

At this stage I have spent several hours trying to repro this issue and have not get anywhere. If you want us to look at this further then I really need you to provide a project that I can open and run to reproduce the issue (preferably a unit test or console app). For example, here is the type of repro code we need to get to in order to address the issue - #4155 (comment).

@Erwandebenaze
Copy link
Author

I understand and I thank you for the time that you spent to help us.
I can't succeed to reproduce the "bug" somewhere else than in the Web application (in unit test it works...) and I don't understand why the bug doesn't appear for you.

Our project isn't very stable that's why it's hard. This problem geeve me headaches and i thought you could maybe help me with just seeing my code.

However if you want to understand the problem I could maybe geeve you a better version in February after our rush.
Do you want it to try to understand or if the problem isn't disturbing me anymore it's not necessary ?

Again, thanks very much for your attention and sorry to geeve you this "draft" code...

@rowanmiller
Copy link
Contributor

Yes, if you are able to provide some code and instructions that can reliably reproduce the issue then please do send them thru. I'll close this one out now and you can either open a new issue or re-open this one later.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants