Click here to Skip to main content
15,885,141 members
Home / Discussions / C#
   

C#

 
GeneralRe: GetValueOrDefault() Throws Pin
Kevin Marois18-Nov-19 8:40
professionalKevin Marois18-Nov-19 8:40 
GeneralRe: GetValueOrDefault() Throws Pin
Richard Deeming18-Nov-19 8:48
mveRichard Deeming18-Nov-19 8:48 
GeneralRe: GetValueOrDefault() Throws Pin
Kevin Marois18-Nov-19 8:54
professionalKevin Marois18-Nov-19 8:54 
GeneralRe: GetValueOrDefault() Throws Pin
Richard Deeming18-Nov-19 9:00
mveRichard Deeming18-Nov-19 9:00 
GeneralRe: GetValueOrDefault() Throws Pin
Kevin Marois18-Nov-19 9:02
professionalKevin Marois18-Nov-19 9:02 
GeneralRe: GetValueOrDefault() Throws Pin
Richard Deeming18-Nov-19 9:04
mveRichard Deeming18-Nov-19 9:04 
GeneralRe: GetValueOrDefault() Throws Pin
Kevin Marois18-Nov-19 9:24
professionalKevin Marois18-Nov-19 9:24 
QuestionDAL Exception Handling Pin
Kevin Marois15-Nov-19 4:33
professionalKevin Marois15-Nov-19 4:33 
I'm curious how you guys do exception handling in your DAL.

My Apps are usually structured like this... The Client (this case a WPF app) calls the BL, which then calls the DAL:

WPF App
private async void AddUser()
{
    UserEntity user = new UserEntity
    {
        FirstName = "Jack",
        LastName = "Stone",
        UserName = "jstone",
        Password = ""
    };

    await Task.Factory.StartNew(() =>
    {
        IBizObj bo = new BizObj(connString);
        bo.AddUser(user);

    }).ContinueWith(task =>
    {
        UserList.Add(user);
    });
}
Bis Layer
public class BizObj : IBizObj
{
    IRepository _repoisitory;

<pre>
public BizObj(string connectionString)
{
    _repoisitory = new FalconRepository(connectionString);
}

public int AddUser(UserEntity entity)
{
    return _repoisitory.AddUser(entity);
}

}
DAL
public int AddUser(UserEntity entity)
{
    using (var dc = GetDataContext())
    {
        int results = 0;

        try
        {
            User user = new User
            {
                FirstName = entity.FirstName,
                LastName = entity.LastName,
                UserName = entity.UserName,
                Password = entity.Password,
                CanLogIn = entity.CanLogIn,
                PasswordChangeDate = entity.PasswordChangeDate,
                CreatedByUserId = 1,
                CreatedDT = DateTime.Now,
            };

            dc.Users.InsertOnSubmit(user);
            dc.SubmitChanges();

            results = user.Id;
        }
        catch (Exception e)
        {
             //<===================================== HANDLE EXCEPTION HERE
        }

        return results;
    }
}
So, the question is wwhat is the correct way to handle the exception on the DAL? Would you handle the exception in the UI, the DAL, both?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.

AnswerRe: DAL Exception Handling Pin
Pete O'Hanlon15-Nov-19 4:40
mvePete O'Hanlon15-Nov-19 4:40 
GeneralRe: DAL Exception Handling Pin
OriginalGriff15-Nov-19 5:04
mveOriginalGriff15-Nov-19 5:04 
GeneralRe: DAL Exception Handling Pin
Kevin Marois15-Nov-19 6:01
professionalKevin Marois15-Nov-19 6:01 
GeneralRe: DAL Exception Handling Pin
OriginalGriff15-Nov-19 6:19
mveOriginalGriff15-Nov-19 6:19 
GeneralRe: DAL Exception Handling Pin
Pete O'Hanlon18-Nov-19 4:43
mvePete O'Hanlon18-Nov-19 4:43 
AnswerRe: DAL Exception Handling Pin
Gerry Schmitz15-Nov-19 5:21
mveGerry Schmitz15-Nov-19 5:21 
GeneralRe: DAL Exception Handling Pin
Kevin Marois15-Nov-19 5:59
professionalKevin Marois15-Nov-19 5:59 
GeneralRe: DAL Exception Handling Pin
Gerry Schmitz16-Nov-19 2:45
mveGerry Schmitz16-Nov-19 2:45 
SuggestionRe: DAL Exception Handling Pin
Richard Deeming15-Nov-19 5:29
mveRichard Deeming15-Nov-19 5:29 
GeneralRe: DAL Exception Handling Pin
Kevin Marois15-Nov-19 5:55
professionalKevin Marois15-Nov-19 5:55 
GeneralRe: DAL Exception Handling Pin
Richard Deeming15-Nov-19 6:43
mveRichard Deeming15-Nov-19 6:43 
QuestionLINQ sort and group dates by month and day, ignore year Pin
Mc_Topaz15-Nov-19 0:38
Mc_Topaz15-Nov-19 0:38 
AnswerRe: LINQ sort and group dates by month and day, ignore year Pin
Richard Deeming15-Nov-19 1:28
mveRichard Deeming15-Nov-19 1:28 
GeneralRe: LINQ sort and group dates by month and day, ignore year Pin
Mc_Topaz15-Nov-19 2:38
Mc_Topaz15-Nov-19 2:38 
QuestionDispose a Tooltip Pin
ConnerMcLoud15-Nov-19 0:32
ConnerMcLoud15-Nov-19 0:32 
AnswerRe: Dispose a Tooltip Pin
OriginalGriff15-Nov-19 2:25
mveOriginalGriff15-Nov-19 2:25 
AnswerRe: Dispose a Tooltip Pin
Gerry Schmitz15-Nov-19 5:41
mveGerry Schmitz15-Nov-19 5:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.