You can use FirstOrDefault
or SingleOrDefault
(if there should be no more than one row matching your Defindex value) to get single row from table:
var row = context.TableName.FirstOrDefault(r => r.Defindex == value);
if (row != null)
// use row.Name;
If you are using default EF provider for SQL Server, then this will generate SQL query
SELECT TOP (1)
[Extent1].[Defindex] AS [Defindex],
[Extent1].[Name] AS [Name],
[Extent1].[MarketPrice] AS [MarketPrice]
FROM [dbo].[TableName] AS [Extent1]
WHERE [DefIndex].[Id] > @value
Same query can be written also this way
var row = context.TableName.Where(r => r.Defindex == value)
.FirstOrDefault();
SingleOrDefault
will try to select top 2 results and it will throw exception if there is more than one row returned.