linqからcsvを使用してエンティティをcsvファイルに出力しています。ソースをループしており、変数PersonalDetails
には6つのレコードがあります。Linq to CSVデータを出力しない
public class PersonalDetails
{
public string LineType { get; set; }
public string EnquirerTitle { get; set; }
public string ForeName { get; set; }
public string Surname { get; set; }
public int? Age { get; set; }
public DateTime? DateOfBirth { get; set; }
public string MaritalStatus { get; set; }
public string HomePhone { get; set; }
public string MobilePhone { get; set; }
public string Email { get; set; }
public string Address { get; set; }
public string Employment { get; set; }
public string Occupation { get; set; }
}
public Boolean CsvOutput(string filename, char delimnator)
{
try
{
CsvFileDescription outputFileDescription = new CsvFileDescription
{
SeparatorChar = delimnator, // tab delimited
FirstLineHasColumnNames = false, // no column names in first record
EnforceCsvColumnAttribute = true,
FileCultureName = "nl-NL" // use formats used in The Netherlands
};
CsvContext cc = new CsvContext();
IQueryable<tblapertureNetAppointment> _personadetails;
var personalDetails = (from _appointments in _dal.apertureNetEntities.tblapertureNetAppointments
select new PersonalDetails()
{
LineType = "Details",
EnquirerTitle = "MR",
ForeName = _appointments.CustomerFirstName,
Surname = _appointments.CustomerLastName,
Age = _appointments.age,
DateOfBirth = _appointments.dob,
MaritalStatus = "Single",
HomePhone = "MobilePhone",
Email = "david.buck[email protected]",
Address = _appointments.Address1 + "," + _appointments.Address2 + "," + _appointments.County + "," + _appointments.PostCode,
Employment = "Developer",
Occupation = "Yes"
}).ToList();
cc.Write(personalDetails,filename,outputFileDescription);
}
catch (Exception ex)
{
return false;
}
return true;
}
ファイルは作成されていますが、実際のファイルにはデータはありません。私はPersonalDetailsここ
あなたは 'CsvContext'を処分する必要があります書き込みのcsvの簡単な方法は? –
.Dispose()と同じように、ドキュメントにはありません。 – rogue39nin
をフラッシュする.writeコマンドがあります。私は 'cc.Write'メソッドを疑うでしょう。あなたは何がうまくいかないかを見つけるためにプログラムをデバッグする必要があります。 –