totoland / linqtoexcel

Automatically exported from code.google.com/p/linqtoexcel
0 stars 0 forks source link

Throw exception instead of returning null value? #17

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.Create a working program based on known spreadsheet column names.
2.One day, the supplier of the spreadsheet changes one of the column 
names, without telling anyone.

What is the expected output? What do you see instead?
Null values are returned for the column that no longer matches. The 
program no longer works properly but the reason why is not immediately 
obvious. Would be better if linqtoexcel threw an exception when this 
happens. (Or, if some people prefer the current behavior, allow a choice 
of behavior as a parameter, when ExcelQueryFactory is constructed.)

What version of the product are you using? On what operating system?
v58. On Windows XP.

Please provide any additional information below.

Original issue reported on code.google.com by jd.r...@gmail.com on 9 Mar 2010 at 5:42

GoogleCodeExporter commented 8 years ago
I don't like the idea of throwing an exception if not all the class properties 
map to
a column in the excel spreadsheet. However, I will begin work on an enhancement 
that
will return the list of column names in an excel spreadsheet. Then you will be 
able
to query the list of column names and see if any have changed.

Original comment by paulyo...@gmail.com on 13 Mar 2010 at 3:01

GoogleCodeExporter commented 8 years ago
Dear Paul,
Nice to see you proposition concerning column name returning. Do you have any 
news according finishing date for this features? kind regards robert

Original comment by robertbi...@gmail.com on 11 Jun 2010 at 2:28

GoogleCodeExporter commented 8 years ago
GetWorksheetNames() and GetColumnNames() methods have been added to the 
IExcelQueryFactory interface to take care of this issue.

It is included in the latest file release: LinqToExcel_1.3.77

Original comment by paulyo...@gmail.com on 13 Jun 2010 at 2:34

GoogleCodeExporter commented 8 years ago
I went ahead and implemented the StrictMapping property which does throw an 
exception if not all columns and class properties map to each other. 

See the documentation for more information: 
http://code.google.com/p/linqtoexcel/wiki/UsingLinqToExcel#Strict_Mapping

Original comment by paulyo...@gmail.com on 13 Jun 2010 at 10:07

GoogleCodeExporter commented 8 years ago
This is implemented in version 1.4.79

Original comment by paulyo...@gmail.com on 13 Jun 2010 at 10:07

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Hello,
I try to use StrictMappingException.in example code below I always haven't 
exception.

BEGIN OF CODE BLOCK

excel.StrictMapping = true;
excel.AddMapping<ExcelBiling>(x => x.InvoiceNo, "Invoice No");
excel.AddMapping<ExcelBiling>(x => x.PhoneNumber, "Phone Number");

var worksheetNames = excel.GetWorksheetNames();
var res = from t in excel.GetWorksheetNames()
          where !t.EndsWith("_")
          select t;
foreach (var item in res)
{
   try 
   {
       var result = from c in excel.Worksheet<ExcelBiling>(item.ToString())
       where c.PhoneNumer == 608008123
       select c;
   }
   catch (LinqToExcel.Domain.StrictMappingException ex)
   {
    string message = ex.Message;
   }
}

END OF CODE BLOCK

As result I see in error Message = "'Invoice No' column is not mapped to a 
property"
Where I'm wrong?
Is my understanding of exception using properly?

kind regards robert

Original comment by robertbi...@gmail.com on 16 Jun 2010 at 9:55

GoogleCodeExporter commented 8 years ago
This is fixed in version 1.4.80

Original comment by paulyo...@gmail.com on 14 Jul 2010 at 11:52