B
Belarmino Vicenzo
Guest
First of all, I'm sorry for the long text.
I'm a noob on DTOs, DALs, BALs, Repository patterns and stuff. So every time I see one info about it, I use it, when I see another, I see if I can use the new method and if(true) Console.Write("I used it"); rsrsrsrs
So, I'm having like a teenager love crisis, I can't have my focus on one info, because I don't have enough experience to guide me through this amount of info.
On one of my post here on MSDN, a user named DA924x, told me about DTOs a few times, and my scavenging for info according my actual skill (I usually don't use info, that makes me learn new info to use that, is just too time consuming sometimes), and I found repository, repository pattern.
I found a very very cool thing Are DTOs the same as using the Repository pattern?
The app that my team is developing will need to make CRUD operations.
I was having problems on the crud, so I decided that I should map the tables by creating the classes, something like EF Model does (EF isn't working on my case, and I passed that, so there's no point on talk about it).
I was seeking to use DTOs, but I use a CRUD Dapper extension and this extension, create a Interface and a class with CRUD operations all from my classes
public class Friend
{
public int FriendID { get; set; }
public string Name { get; set; }
public string City { get; set; }
public string PhoneNumber { get; set; }
}
public interface IFriendRepository
{
List<Friend> SelectFriend();
void InsertFriend(Friend friend);
void UpdateFriend(Friend friend);
void DeleteFriend(Friend friend);
}
public class FriendRepository : IFriendRepository
{
public List<Friend> SelectFriend()
{
// Select
}
public void InsertFriend(Friend friend)
{
// Insert
}
public void UpdateFriend(Friend friend)
{
// Update
}
public void DeleteFriend(Friend friend)
{
// Delete
}
}
I just remove the logic, but it all work as expected. So I copied the same technique to my team's project (the part I'm working in) but now I have a class like this one:
public class Animal
{
public int Id{ get; set; }
public string Name { get; set; }
public int IdCategory { get; set; }
}
public class CategoryOfAnimal
{
public int Id{ get; set; }
public string Category{ get; set; }
}
The problem is, when I do the select using the technique I just said, I have to write something like this:
select a.id, a.name, c.category from animal, categoryofanimal where a.IdCategory=c.id
But I have to return it as a whole (with both animal and categoryofanimal) to the end consumer, I could just alter the class, but Its seems not right.
So I'm thinking that I could use something I could only transfer the final data, something like a database view.
My superior here at work is someone that only write code, he doesn't look for patterns and stuff, test classes (I'm not good on that, but I try to write them). Probably my superior here he is coding like things should exit and now how thing should be.
For example is he probably has a class or something with both Animal and Category in one place without the real ones (at least this is not the way it must be in database design techniques).
Before all, I'm sorry one more time for the long text.
I just don't have no one to talk about it by voice.
And second, please define like you're explaining to a child (please) what is, when its used, what does serves for: DTOs, BALs and repositories.
And then give me a solution of my problem (please) with simple examples.
Please, I just now how to code, learning the rules is the hardest thing, I might know what is a bool, but not to use it perfectly. That's my problem right now with layered applications and CRUD.
Please don't use advanced things, I understand the code, but this DTOs and repository thing is really messing with me.
And if here's is not the place to ask such questions, please point me to the right one.
Please, it's my 1st job and I really need to start writing better code, even if only I can tell.
----
BP-LP 2005/2016 @ll rights reserved
Continue reading...
I'm a noob on DTOs, DALs, BALs, Repository patterns and stuff. So every time I see one info about it, I use it, when I see another, I see if I can use the new method and if(true) Console.Write("I used it"); rsrsrsrs
So, I'm having like a teenager love crisis, I can't have my focus on one info, because I don't have enough experience to guide me through this amount of info.
On one of my post here on MSDN, a user named DA924x, told me about DTOs a few times, and my scavenging for info according my actual skill (I usually don't use info, that makes me learn new info to use that, is just too time consuming sometimes), and I found repository, repository pattern.
I found a very very cool thing Are DTOs the same as using the Repository pattern?
The app that my team is developing will need to make CRUD operations.
I was having problems on the crud, so I decided that I should map the tables by creating the classes, something like EF Model does (EF isn't working on my case, and I passed that, so there's no point on talk about it).
I was seeking to use DTOs, but I use a CRUD Dapper extension and this extension, create a Interface and a class with CRUD operations all from my classes
public class Friend
{
public int FriendID { get; set; }
public string Name { get; set; }
public string City { get; set; }
public string PhoneNumber { get; set; }
}
public interface IFriendRepository
{
List<Friend> SelectFriend();
void InsertFriend(Friend friend);
void UpdateFriend(Friend friend);
void DeleteFriend(Friend friend);
}
public class FriendRepository : IFriendRepository
{
public List<Friend> SelectFriend()
{
// Select
}
public void InsertFriend(Friend friend)
{
// Insert
}
public void UpdateFriend(Friend friend)
{
// Update
}
public void DeleteFriend(Friend friend)
{
// Delete
}
}
I just remove the logic, but it all work as expected. So I copied the same technique to my team's project (the part I'm working in) but now I have a class like this one:
public class Animal
{
public int Id{ get; set; }
public string Name { get; set; }
public int IdCategory { get; set; }
}
public class CategoryOfAnimal
{
public int Id{ get; set; }
public string Category{ get; set; }
}
The problem is, when I do the select using the technique I just said, I have to write something like this:
select a.id, a.name, c.category from animal, categoryofanimal where a.IdCategory=c.id
But I have to return it as a whole (with both animal and categoryofanimal) to the end consumer, I could just alter the class, but Its seems not right.
So I'm thinking that I could use something I could only transfer the final data, something like a database view.
My superior here at work is someone that only write code, he doesn't look for patterns and stuff, test classes (I'm not good on that, but I try to write them). Probably my superior here he is coding like things should exit and now how thing should be.
For example is he probably has a class or something with both Animal and Category in one place without the real ones (at least this is not the way it must be in database design techniques).
Before all, I'm sorry one more time for the long text.
I just don't have no one to talk about it by voice.
And second, please define like you're explaining to a child (please) what is, when its used, what does serves for: DTOs, BALs and repositories.
And then give me a solution of my problem (please) with simple examples.
Please, I just now how to code, learning the rules is the hardest thing, I might know what is a bool, but not to use it perfectly. That's my problem right now with layered applications and CRUD.
Please don't use advanced things, I understand the code, but this DTOs and repository thing is really messing with me.
And if here's is not the place to ask such questions, please point me to the right one.
Please, it's my 1st job and I really need to start writing better code, even if only I can tell.
----
BP-LP 2005/2016 @ll rights reserved
Continue reading...