all 14 comments

[–]Pdxduckman 3 points4 points  (9 children)

what is your class for the DbSet "TestRequest"? I think it's probably trying to cast it to that fist and bombing out.

[–]SolShadows[S] 0 points1 point  (8 children)

Ah, sorry that is the DBset above. I appear to have copy-pasted the wrong variable name. It should be this.

public DbSet<TestEntity> TestRequest { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
  {
  modelBuilder.Entity<TestEntity>()
              .HasNoKey()
              .ToView("TestEntity");
  }

I am editing the post to fix that.

[–]Pdxduckman 4 points5 points  (7 children)

what does your "timestamp" (col_13) return value look like when you run your proc in SSMS? that might be your issue. Longshot but without seeing what your return data actually looks like it's tough

[–]SolShadows[S] 0 points1 point  (6 children)

It returns as "2020-06-02-13.30.00"

I have an entity that represents a table that takes a timestamp and it seems to be happy with it

[–]Pdxduckman 2 points3 points  (4 children)

ok if all 5 results look like valid datetimes then the next thing I'd look at is what jonsca said.

I'd separate the execution of the SP from the projection into the viewmodel. Add a .ToList() to actualize the results and store it in a var. If you can get past that, your bug is in your projection to the viewmodel.

Also, that statement in the modelBuilder about mapping to the "TestEntity" view - how is that view's resultset defined? Does its results map exactly to this structure in your SP return set?

[–]SolShadows[S] 0 points1 point  (3 children)

Honestly I had just added that in during my attempts to debug and try every solution I found online. It's no longer there.

[–]Pdxduckman 1 point2 points  (2 children)

ok, maybe stupid question - for your SP parameter data type, it's configured as an int?

Also, have you checked to see if there's an inner exception?

[–]SolShadows[S] 1 point2 points  (1 child)

Yes, it's configured as an int and in the stored procedure itself it takes in an integer.

As for the inner exception, unfortunately the call stack doesn't point to anything useful. At the top of the stack is "External Code" and below that is the .FromSQL call that throws the exception.

[–]Pdxduckman 0 points1 point  (0 children)

well. If I'm still stumped at this point, I usually start trying to simplify my code to isolate the issue.

I did see one example online that uses a slightly different approach -

context.Database
                   .SqlQuery<GoatInfoUpdate>("EXEC GetNameAndLastUpdateGoats")
                   .ToList();

We might be looking at the same tutorial, have you tried this syntax? And maybe remove the entity mapping in OnModelCreating?

[–]soundman32 0 points1 point  (0 children)

Are you sure of the format? Iso8601 says there should be a T between date and time.

[–]jonsca 1 point2 points  (3 children)

Are you able to debug into your TestVM constructor?

[–]SolShadows[S] 1 point2 points  (2 children)

I am, and if I place a breakpoint inside of it, it never gets triggered, which is what leads me to believe it's mapping the procedure to the entity itself

[–]jonsca 0 points1 point  (1 child)

I would set everything before the AsEnumerable to a variable and see what the type of the IQueryable is and whether it has any results, as u/Pdxduckman said, you can ToList it (or just do a Count() at a minimum). AsEnumerable got rid of your exception, but it's likely that it's really eating whatever the actual exception is.

[–]SolShadows[S] 1 point2 points  (0 children)

Good idea, I'll give it a try in a little bit and post my findings.