开发者

Innerjoin in Linq-to-sql for this in asp.net mvc?

I use asp.net mvc... How to write an inner join in linq-to-sql for this sql query

select M.Mat_id,M.Mat_Name,T.Name as Measurement,M.Mat_Type as Description 
 from Material as M inner join MeasurementTypes as T 
  on M.MeasurementTypeId = T.Id where M.Is_Deleted=0

And my repository class has this,

    public class ConstructionRepository
    {
        private CRDataContext db = new CRDataContext();
        public IQueryable<Material> FindAllMaterials()
        {
            return db.Materials;
        }
    }

My result db.Materials is the table data.. I dont want that i want to innerjoin with another table and show the data....

public class ConstructionRepository
 {
    private CRDataContext db = new CRDataContext();
     public IQueryable<Material> FindAllMaterials(开发者_运维知识库)
    {
                //inner join query
     }
    }

Any suggestions...


This will return anonymous types with the details you've specified in your SQL query but you may prefer to simply return the material objects themselves.

from material in db.Materials
from measurementType in material.MeasurementTypes
where material.Is_Deleted = false
select new {
    material..Mat_id,
    material.Mat_Name,
    Measurement = measurementType.Name,
    Description = material.Mat_Type
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜