0

I have a table-valued function that returns entities that contain complex types. I am trying to figure out the best way to load this data into my code-first application as entities.

I tried the Code First Functions project, but it doesn't support entities with complex types.

I also tried SqlQuery, e.g.,

context.MyEntities.SqlQuery("SELECT * FROM [TableValuedFunction]()")

but that also doesn't support complex types, apparently. I get an InvalidOperationException that says, "Only properties of primitive or enumeration types are supported."

My use case is pretty limited since this will be readonly data. I don't need things like change tracking or even an IQueryable instance. I can live with just a single entity that I display and then discard.

I think I can probably get around this "manually" by just executing the SQL, get the data back in a DataTable, and using that to create my entities. But that's obviously undesirable for many reasons, not least of which is that it's basically ditching Entity Framework entirely.

Is there any other way to create my entities in a more automated fashion?

Here is a simple example that uses the Code First Functions project, but fails.

Kris Harper
  • 5,672
  • 8
  • 51
  • 96

0 Answers0