views:

35

answers:

2
public ActionResult Index()
    {
        testEntities6 devicesEntities = new testEntities6();
        List<DevicesModel> devicesModel = new List<DevicesModel>();
        var device_query = from d in devicesEntities.device
             join dt in devicesEntities.devicetype on d.DeviceTypeId equals dt.Id
             join l in devicesEntities.location on d.Id equals l.DeviceId
             join loc in devicesEntities.locationname on l.LocationNameId equals loc.Id
                           where l.DeviceId == d.Id
                           select new {
                               //devices
                               d.Id,
                               d.DeviceTypeId,
                               d.SerialNumber,
                               d.FirmwareRev,
                               d.ProductionDate,
                               d.ReparationDate,
                               d.DateOfLastCalibration,
                               d.DateOfLastCalibrationCheck,
                               d.CalCertificateFile,
                               d.Notes,
                               d.TestReportFile,
                               d.WarrantyFile,
                               d.CertificateOfOriginFile,
                               d.QCPermissionFile,
                               d.Reserved,
                               d.ReservedFor,
                               d.Weight,
                               d.Price,
                               d.SoftwareVersion,
                               //devicetype
                               dt.Name,
                               dt.ArticleNumber,
                               dt.Type,
                               //location
                               l.StartDate, //AS LastStartDate,
                               l.LocationNameId,
                               //locationname
                               Loc_name = loc.Name //AS CarrentLocation
                           };

        foreach (var dv in device_query) {
            devicesModel.Add(new DevicesModel(
                //device
                DeviceTypeId = dv.DeviceTypeId, 
      /*Why I have this error: The name 'DeviceTypeId' does not exist in the current context*/
                ...
                ));

        }
        return View(devicesModel);
    }

Model:

public class DevicesModel
 {
//device
public int deviceTypeId;
public int id;
public int serialNumber;
public string firmwareRev;
public DateTime productionDate;
public DateTime reparationDate;
public DateTime dateOfLastCalibration;
public DateTime dateOfLastCalibrationCheck;
public int calCertificateFile;
public string notes;
public int testReportFile;
public int warrantyFile;
public int certificateOfOriginFile;
public int qCPermissionFile;
public int BReserved;
public string reservedFor;
public double weight;
public int price;
public string softwareVersion;
//devicetype
public string name;
public string qrticleNumber;
public string type;
//location
public DateTime startDate;
public int locationNameId;
//locationname
public string loc_name;

public DevicesModel(){}

//device
public int DeviceTypeId{get;set;}
public int Id { get; set; }
public int SerialNumber { get; set; }
public string FirmwareRev { get; set; }
public DateTime ProductionDate { get; set; }
public DateTime ReparationDate { get; set; }
public DateTime DateOfLastCalibration { get; set; }
public DateTime DateOfLastCalibrationCheck { get; set; }
public int CalCertificateFile { get; set; }
public string Notes { get; set; }
public int TestReportFile { get; set; }
public int WarrantyFile { get; set; }
public int CertificateOfOriginFile { get; set; }
public int QCPermissionFile { get; set; }
public int bReserved { get; set; }
public string ReservedFor { get; set; }
public double Weight { get; set; }
public int Price { get; set; }
public string SoftwareVersion { get; set; }
//devicetype
public string Name { get; set; }
public string ArticleNumber { get; set; }
public string Type { get; set; }
//location
public DateTime StartDate { get; set; }
public int LocationNameId { get; set; }
//locationname
public string Loc_name { get; set; }
}
+1  A: 

Its because you're creating an anonymous object in your linq "Select" clause. I think you want to create an instance of your DevicesModel class, e.g.

...
where l.DeviceId == d.Id
select new DevicesModel {
//devices
Id = d.Id,
...
JonoW
What (in this case) I write in foreach statement ie, what put in: return View(???)
Ognjen
Sorry I don't quite understand what you mean?
JonoW
@JonoW: tnx, I resolved my problem
Ognjen
+1  A: 

I think you intend to use curly brackets instead of round brackets.

new DevicesModel 
{
   //device
   DeviceTypeId = dv.DeviceTypeId, 
   ...
}

or are you trying to use named arguments in C#4?

bruno conde