0

We are using POCO class to call SQL view, but getting unexpected values in one of the column across the records. not seeing the issue when the same view executed in the SQL server.

I read that we can define a primary key / property reference in the edmx file ? but we done have edmx file as we use POCO file. in that case any workaround in POCO class ?

even using ADO .Net to call sql view works fine, not sure why we have issue when we use POCO class.

Appreciate your inputs.

chint
  • 47
  • 1
  • 8
  • Post a minimal example. Is this code first then I assume? – Steve Greene Jun 07 '17 at 20:03
  • Yes it is code first. var variable = _context..ToList().Where(x => x.colmun1== "12345678"); this is the code, we are seeing above issue in it. please can you now suggest based on additional details. – chint Jun 08 '17 at 12:32
  • There shouldn't be anything different about using a SQL view versus a table. Do you have any annotations or fluent code to show? For the field that is not being populated correctly what is the type and name in the class and database? – Steve Greene Jun 08 '17 at 13:22
  • Datatype is string and same at DB and .Net end. i dont think we have annotations. this issue, i read is solvable, if we have edmx file, need to set reference key in it. not sure how to do same when one has POCO classes. – chint Jun 09 '17 at 05:46
  • Right, you can not reference a View unless you define a key. This can be done via convention (field name called ID or Class + ID), annotation or fluent code. – Steve Greene Jun 09 '17 at 14:37
  • thank you, Steve. it will help if you can provide an example or elaborate. – chint Jun 12 '17 at 05:32
  • [Here's one](https://stackoverflow.com/questions/7461265/how-to-use-views-in-code-first-entity-framework). Might help if you post your model and indicate problem field. – Steve Greene Jun 12 '17 at 13:38

0 Answers0