A
Andy B.
I have a situation where I need to return different types of data from a
function depending on what happened with code execution. I will give a
little example of what I need to do. I use the entity framework for most of
my data access but I wouldn't think that makes a difference on return types.
I will use this example on the method AddNewsArticle.
1. The function starts to run.
2. Chheck to see that all parameters are not nothing. If they are trap
argumentException.Message and return it. Otherwise continue.
3. Create the NewsArticle object and attempt to add it to the database. If
anything fails, return the sqlException.Message. Otherwise continue.
4. If the Create NewsArticle and add it to the database succeeds, return the
number (Integer) from ObjectContext.SaveChanges().
Of course logging would be involved as well but for now I at least need to
let the user know why things happened/didn't happen. Is there a way to do
this without turning explicit/option strict off and not always return
strings (convert all return data types to a string)?
function depending on what happened with code execution. I will give a
little example of what I need to do. I use the entity framework for most of
my data access but I wouldn't think that makes a difference on return types.
I will use this example on the method AddNewsArticle.
1. The function starts to run.
2. Chheck to see that all parameters are not nothing. If they are trap
argumentException.Message and return it. Otherwise continue.
3. Create the NewsArticle object and attempt to add it to the database. If
anything fails, return the sqlException.Message. Otherwise continue.
4. If the Create NewsArticle and add it to the database succeeds, return the
number (Integer) from ObjectContext.SaveChanges().
Of course logging would be involved as well but for now I at least need to
let the user know why things happened/didn't happen. Is there a way to do
this without turning explicit/option strict off and not always return
strings (convert all return data types to a string)?