Entity Framework is it possible using entity populated from a stored procedure but no physical table in database - entity-framework

I want to utilize the capability of EF to populate an entity from calling a stored procedure, but this entity does not need to map to a physical table, as it only exists in my application.
Is it achievable?
Many thanks.

Related

Informix Stored procedure with Entity Framework

I am new to Informix stuff and I have a legacy database (IBM Informix) and there are thousands of stored procedures written. Now I am trying to create the model class using Entity framework database first approach.
The problem I am facing now is;
When I am trying to add stored procedures from Update Model from Database, noting is list down in the Stored Procedures and Functions. Further I have checked with the server and found that all stored procedures are stored in sysprocedures table.
My questions are;
How can I import these procedures into Entity framework?
Is it possible to invoke stored procedure without importing?

entity framework no PK's on tables

I'm using VS2012 and creating a sample Entity Framework project that reads and writes to some tables that are used for import purposes. and do not have PK's or FK's in them - just null/notnull on the columns.
Can/should EF be made to insert records on these tables without that cryptic error:
Unable to update the EntitySet because it has a DefiningQuery
and no element exists in the
element to support the current
operation.
Or should I be looking elsewhere for database I/O?
Thanks!
Corey.

Stored procedures with joined data in entity framework

We currently have a system with quite large database and stored procedures are used both for CUD and querying. DataSets are used to retrieve the results from the SP querys.
Now we are looking into developing another project against the same database using Entity Framework. When querying the database, the stored procedures often perform a lot of joins to gather some fields not in the target table, but data from the joined tables that is needed by the client in some way. When using DataSets, all the fields returned by the SP was included in the DataTable. So the DataTable doesn't actually match the target database table.
What is the correct way of handling this scenario in EF? When creating my model, the entities are mapped to each table which as mentioned above only sometimes matches the result of the SP. Can I add the "additional" fields of the SP query result to the entity class as properties and have them filled by the query but with these properties being excluded when it comes to CUD on the specific entity type? Seems like the EF-way, if queried through LINQ to Entities and not SPs, would be to have entity instances with relational properties to the joined entities so that using those "additional" properties would be done by navigating the relational properties?
You can define an arbitrary complex type (just a class that's generated for you, to match the columns and datatypes returned by the stored procedure) as the return type for your stored procedure in Entity Framework (as of version 4 and newer) - no problem here.
See Stored Procedures in the Entity Framework for a great explanation of all things related to using stored procedures in Entity Framework.

how to save EF (STE) entities in to temporary tables

is there a way, how to save EF (STE) entities in to temporary tables?
I'm trying to achieve this:
1) save my STE to temporary tables
2) run some stored procedures on them
3) depending on result from procedures, do something else..
Thank you.
EF will not handle this. EF saves the entity to table(s) defined in mapping but the mapping is defined at design time. You cannot decide to save the entity to other table at runtime through EF without changing its mapping and that would be highly inefficient - changing mapping at runtime is not a supported use case so it is quite complicated and moreover applying a new mapping is the most expensive operation in EF.
You need just another stored procedure to insert your data to temporary table. Depending on the logic you expect you can either map that procedure to insert operation for the entity (but in such case your procedure will be used every time you insert a new entity) or simply execute it directly.

Accessing runtime-created tables with Entity Framework

We have an application that creates new tables at runtime, but always with the same table schema. The only thing that varies from one of these tables to the next is the table name. Is it possible to access these tables using Entity Framework, specifying which table to access by name?
Entity Framework is not designed for DDL, it's an ORM tool for data access. You would want to use a simple ADO.NET query to create/drop the table.
Creating and dropping tables for every user session will make your log file grow very big very fast. I would consider carefully the reasons you think this is necessary. If the data is temporary, why not save the Session ID in each row and truncate the table on a daily basis?
UPDATE:
No, not really. The Entity Data Model is not dynamic, it's a static XML document that describes the structure of the database. If you want to interact with a table with a dynamic name, you're going to have to stick to "classic" ADO.NET.
With Linq to SQL I guess it would be possible with a stored procedure taking the table Name as a parameter.
A nice post about SP in L2SQL: http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx
I don't know if that feature exists in EF.