Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
More EF Perplexities (a sequel)
Message
Information générale
Forum:
ASP.NET
Catégorie:
Entity Framework
Versions des environnements
Environment:
C# 5.0
OS:
Windows Server 2016
Network:
Windows Server 2016
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01646596
Message ID:
01646604
Vues:
31
Many thanks.

But I'm really trying to execute a Scalar Returning Function, that for some reason does not get generated in the EF context.




>>I generated EF Entities from a Database. Now I would like run a raw sql against that same database that is not included in the generated entities.
>>I thought I'd use the DbContext .Database.SqlQuery method, but that throws an exception (unitntionalCodeFirsteExcption.
>>
>>"The context is being used in Code First mode with code that was generated from an EDMX file for either Database First or Model First development. "
>>
>>So does that mean one cannot access the database in this way., or is there a approach hidden somewhere that I am still to discover?
>
>Hmm. I just tried querying a table that was not in the model and, providing you have a C# class that matches the names/types of the returned columns, it seems to work. eg:
        public class Carriers
>        {
>            public string Name { get; set; }
>            public string DepProv { get; set; }
>        }
then this is OK:
var yyy = PGD.Database.SqlQuery<Carriers>("SELECT Name,DepProv FROM dbo.Carriers").ToList();

If things have the tendency to go your way, do not worry. It won't last. Jules Renard.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform