I’m new to c#, linq, and EF4, so please bear with me. I’m sure it’s something really simple, but not seeing it.
The stored procedure I’m replacing does a SELECT INTO to query a bunch of data, do some simple transformations, and then output the results into another table. Then, this set of data is returned for local processing in the code.
I have a query that pulls my data into an anonymous type and handles all of the transformations. But, how do I go about sending that data up into the results table?
Initially, I thought of using the entity type to store my initial results. But I have extra fields that I need for local processing that will not be stored in the result table.
Thanks to any EF masters who care to take a crack at this for me!
edit: Here’s some pseudo code based on Morteza’s help, but doesn’t seem to move the data —
var ctx = new ReportEntities();
var query = from s in ctx.Source
select new
{
s.SourceID,
s.OtherStuff
};
query.ToList().Select(q => new Report()
{
SourceID = q.SourceID,
OtherStuff = q.OtherStuff
});
ctx.SaveChanges();
As of EF4 you can update your model with your individual stored procedures and import them as functions. I think the easiest way would be to take advantage of this new feature and create a second procedure that accepts the result data as parameters and save them into the result table. So you can call this function once you done with your data processing.
Update: