Table-valued function

0

I need to create user-defined functions with table values, can I create from EF? Or do I only believe it by transaction sql and then represent it in the model? How would you work with EF in this case?

Note: I am working with EF approach code firts.

CREATE FUNCTION dbo.fnDetalleCaja(@desde datetime2, @hasta datetime2) RETURNS TABLE AS RETURN (SELECT .... WHERE ...)

The entity DetalleCaja would come out of that function. For EF it should be the same thing for all purposes.

For this case I create my table-value funtion by transact sql code and then I create my entity in my feature layer.

What is the way to work in this case?

    
asked by Pedro Ávila 12.05.2016 в 16:25
source

1 answer

0

Having the instance of the db from the EF context you could execute commands

Raw SQL Queries

string query = "CREATE FUNCTION dbo.fnDetalleCaja(@desde datetime2...";

using (var context = new xxContext()) 
{ 
   context.Database.ExecuteSqlCommand(query);
}

> > > > > > That code should be executed every time i run the system, i guess it should work as map mapping is done, in which EF always checks if the db is created and the tables?

If it should be created when the structure is defined, you will need to implement it in Migrations

Code First Migrations

    
answered by 12.05.2016 / 17:25
source