Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

How can I hide certain fields when accessing database from DbContext

$
0
0

In my database I have relations, for example, I have a table like:

CarId, Model, Manufacturer, Owner where Owner is a foreign key to another table. 

I have a DbSet<Car>

How can I select all columns without Owner in my get action using LINQ?

[HttpGet("[action]")]
public IEnumerable<object> Cars()
{
    return _db.Cars.Select(car => new { Id = car.CarId, Model = car.Model, Manufacturer = car.Manufacturer }).AsEnumerable();
}


Is this the right way of doing it? I use Entity Framework Core.


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>