The alias column does not map a property for an object when using SqlQuery in the Entity Framework

I am using a raw SQL statement in which I have aliases called "Distance" that I would like to store the value in a new property in a partial entity class. However, when I execute the query, the entity structure displays everything except this column with an alias. What should I do to map a column to the Distance alias for the Distance property in my class?

Partial class

 [MetadataType(typeof(ParishMD))]
    public partial class Parish
    {

        public List<SelectListItem> States { get; set; }
        public double Distance { get; set; }

        .........
    }

Controller class method

string SQL = "select * from (select *, Distance = ((ACOS(SIN({0} * PI() / 180) * SIN(lat * PI() / 180) + COS({0} * PI() / 180) * COS(lat * PI() / 180) * COS(({1} - Long) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) from dbo.Parish) t where Distance < 10 order by Distance asc";

 SqlParameter latParam = new SqlParameter("latitude", latitude);
 SqlParameter lngParam = new SqlParameter("longitude", longitude);
 object[] parameters = new object[] { latitude, longitude };


 var parishes = db.Parish.SqlQuery(SQL, parameters);

12 , EDMX, , . Distance , EDMX. , .

!

+3

All Articles