Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I don't do EF, so I am focusing on the code only. But nevertheless maybe this will help you in doing joins with EF: how-to-join-multiple-tables-using-repository-pattern-entity-framework how-to-join-multiple-tables-using-repository-pattern-entity-framework

  • Based on the naming guidelines input parameters should be named using camelCase casing. So
public List<int> GetUserPrevileges(string UserName) 

should be

 public List<int> GetUserPrevileges(string userName)

The same is true local varaiables like Privs but in addition you shouldn't shorten your varaiables names because you are reducing the readability of your code. So better use privileges instead of Privs.

  • This if..else
if (Privs.Any())
{
 return Privs.ToList();
}
else
{
 return null;
}

does not add real value. Why do you want to return null? It would be much easier for the calling code if you return an empty List for the case that there aren't any privileges which match the requirement.

If the IQuerable<T> doesn't contain any items, a call to ToList() will just create an empty list.

If you use the returned List<> to just iterate over the items, you won't even need a check if it is empty.

I don't do EF, so I am focusing on the code only. But nevertheless maybe this will help you in doing joins with EF: how-to-join-multiple-tables-using-repository-pattern-entity-framework

  • Based on the naming guidelines input parameters should be named using camelCase casing. So
public List<int> GetUserPrevileges(string UserName) 

should be

 public List<int> GetUserPrevileges(string userName)

The same is true local varaiables like Privs but in addition you shouldn't shorten your varaiables names because you are reducing the readability of your code. So better use privileges instead of Privs.

  • This if..else
if (Privs.Any())
{
 return Privs.ToList();
}
else
{
 return null;
}

does not add real value. Why do you want to return null? It would be much easier for the calling code if you return an empty List for the case that there aren't any privileges which match the requirement.

If the IQuerable<T> doesn't contain any items, a call to ToList() will just create an empty list.

If you use the returned List<> to just iterate over the items, you won't even need a check if it is empty.

I don't do EF, so I am focusing on the code only. But nevertheless maybe this will help you in doing joins with EF: how-to-join-multiple-tables-using-repository-pattern-entity-framework

  • Based on the naming guidelines input parameters should be named using camelCase casing. So
public List<int> GetUserPrevileges(string UserName) 

should be

 public List<int> GetUserPrevileges(string userName)

The same is true local varaiables like Privs but in addition you shouldn't shorten your varaiables names because you are reducing the readability of your code. So better use privileges instead of Privs.

  • This if..else
if (Privs.Any())
{
 return Privs.ToList();
}
else
{
 return null;
}

does not add real value. Why do you want to return null? It would be much easier for the calling code if you return an empty List for the case that there aren't any privileges which match the requirement.

If the IQuerable<T> doesn't contain any items, a call to ToList() will just create an empty list.

If you use the returned List<> to just iterate over the items, you won't even need a check if it is empty.

Source Link
Heslacher
  • 50.9k
  • 5
  • 83
  • 177

I don't do EF, so I am focusing on the code only. But nevertheless maybe this will help you in doing joins with EF: how-to-join-multiple-tables-using-repository-pattern-entity-framework

  • Based on the naming guidelines input parameters should be named using camelCase casing. So
public List<int> GetUserPrevileges(string UserName) 

should be

 public List<int> GetUserPrevileges(string userName)

The same is true local varaiables like Privs but in addition you shouldn't shorten your varaiables names because you are reducing the readability of your code. So better use privileges instead of Privs.

  • This if..else
if (Privs.Any())
{
 return Privs.ToList();
}
else
{
 return null;
}

does not add real value. Why do you want to return null? It would be much easier for the calling code if you return an empty List for the case that there aren't any privileges which match the requirement.

If the IQuerable<T> doesn't contain any items, a call to ToList() will just create an empty list.

If you use the returned List<> to just iterate over the items, you won't even need a check if it is empty.

lang-cs

AltStyle によって変換されたページ (->オリジナル) /