Reputation:
I would like to run a SQL statement using CF. But the CF is not fixing related entities. How can I achieve this? Can I use DbConnection to manually run my statement and fix related entities ?
Upvotes: 0
Views: 852
Reputation: 364319
You can execute multile SQL statements to get relations as well.
var entity = context.Database.SqlQuery<MyEntity>("SELECT ...");
var relatedEntities = context.Database.SqlQuery<MyRelatedEntity>(
"SELECT ... WHERE EntityId = @id", new SqlParemater("id", entity.Id));
If you use DbConnection
and execute that SQL as DbCommand
you will have to use DbDataReader
and create entities in the old ADO.NET way. No mapping will be done for you.
Upvotes: 2