« first day (1282 days earlier)      last day (3665 days later) » 

6:42 AM
If anyone knows of a good online resource that tells/shows you how to setup a repository pattern (preferably not as separate projects) for database access in EF 6, I would be very grateful. I've only been able to find convoluted examples.
 
 
8 hours later…
2:50 PM
hello, in that question: http://stackoverflow.com/questions/23118033/nullreferenceexception-error-in-asp-net-mvc
my "user" variable is null, but I can't understand why it is null. Where is my mistake , can anyone explain?
 
because there was no user found with the given emailadress?
 
although I enter correct email adress it is null
I added email adress to database in configuration.cs like that:
protected override void Seed(BlogData.BlogDataContext context)
{ var user = new User
{
Username = "Admin",
Password = FormsAuthentication.HashPasswordForStoringInConfigFile("pass", "MD5"),
ConfirmPassword = FormsAuthentication.HashPasswordForStoringInConfigFile("pass", "MD5"),
Email = "mailadresiniz@mailadresiniz.com",
IsActive = true,
IsAdmin = true
};
context.Users.Add(user);
}
 
did you do context.SaveChanges() ?
 
no, I think I dont need because username and password is saved and they dont create a problem during logging in.
 
3:13 PM
do anyone have an idea about this issue?
 
what is the question?
why user is null?
 
yes my problem isthat user is null
 
how do you know that?
wait, is user null in the code you posted here, or in that question on SO?
 
I cant understand why it is null, ı think there isnt any reason for being null
 
In which piece of code is it null, in the code above, where you construct a new object, or in the question on SO, where you look up the user by email?
 
3:29 PM
in the question it is null
 
Ok, have you verified that there is a user in the database with the given email address, other than that code?
ie. SQL, or just browsing the data through the management tools for the database engine?
 
no I havent, but I have login system and current username and password doesnt create a problem so email must be in my opinion
 
do you log in by username or by email address?
and btw, you should introduce a salt in that hashing.
 
by username
what do you mean with "salt" ?
 
one thing at a time
so being able to log in doesn't mean that the email exists in the database
ie. the user row must have the wrong email address
can you verify that the right email address is on that row?
 
3:40 PM
there is one user in database and its username, password and email adress are registered in same time in configuration.cs
 
have you verified that the row in the database actually have the right email address?
 
excluding my remarks above , no . How can I verify in different way?
 
Don't you have SQL access to the database?
 
4:03 PM
yes ı have and I have just verified
 
so it has the right email address?
 
yes
 
ok, can you execute a statement to retrieve the user by its email address, using SQL?
ie. something like
select * from users where email_address = 'your.email@address.here'
and see if that works?
 
yes it works. so where is my mistake? why user is null ? I guess I am going crazy :)
 
Well, let me point out the obvious
Your .NET code failed to retrieve the user by its email address
so since we've verified that SQL works, and you can retrieve the user by the email address that way, my next step would be to find out which SQL statement your repository code ended up executing.
 
4:10 PM
Can problem be in the GetUserByEmail method?
 
I have no idea
 
if you examined all codes, could you see something wrong?
 
I don't know, but I don't want to
Did you verify what SQL statement your repository code ended up executing?
 
Sorry, I dont understand what you mean by repository code
 
What you have called a user service
the GetUserByEmail method, it will end up executing SQL against the database. Have you verified what that SQL statement looks like?
 
4:16 PM
Noi I havent how can I verify?
 
I don't know, it depends on what kind of technology you're using for your data access
 
I am using SQL Server Data Tools
 
Does that generate the .NET code to access your database?
What I mean is, that "Get" method, where does that come from?
var user = _userRepository.Get(x => x.Email == email);
that Get method
 
it comes from _userRepository interface class
public interface IRepository<T> where T : class
{
void Add(T entity);
void Attach(T entity);
void AttachAndApplyChanges(T emptyEntity, T updatedEntity);
void Delete(T entity);
void Delete(Func<T, Boolean> predicate);
T GetById(long id);
T Get(Func<T, Boolean> where);
IEnumerable<T> GetAll();
List<T> GetMany(Func<T, bool> where);
IQueryable<T> Query();
void Include(params string[] paths);
}
}
sorry IRepository
 
Do you understand what my question means? Do you understand what I'm asking?
How does the Get method work? How does it access the database? Is it using entity framework? linq2sql? hand-written SQL somewhere? Some other ORM or framework?
 
4:33 PM
I cant understand some of your questions, because I am very new at .NET, sorry.
public T Get(Func<T, Boolean> where)
{
return ApplyInclude().Where(where).FirstOrDefault();
}
it must be linq
 
What is the base class for the class that has that method?
 
repository class it starts with:
public class Repository<T> : IRepository<T> where T : class
it is the class that get method is defined
 
ok, let me state my question again
Get has to end up as SQL. Where is that SQL generated?
Can you please trace the method calls to the point where either you disappear into Linq2SQL, EF, or something similar, or end up with a string of SQL? Without me having to ask you for each step of that trace?
In this case it looks like ApplyInclude does some tricks. But there is no point in you dumping that code as well, and me having to ask for the next method, you need to follow the breadcrumbs of your code to this.
or you can hook up logging to your framework
or you can hook up a profiler to your database
 
protected IQueryable<T> ApplyInclude()
{
var result = _dbset.AsQueryable();

if (_paths != null && _paths.Length > 0)
{
result = _paths.Aggregate(result, (current, path) => current.Include(path));
}

return result;
}

and asqueryable comes from system.linq.queryable class , is it possible or necessary to go deep?
 
What is the base class of the object in _dbset?
and what is the type of _dbset?
 
4:59 PM
it is defined in repository class and it is defined like that:
private readonly IDbSet<T> _dbset; and IDbSet is the part of system.entity class
 
I have no idea what the System.Entity class is. Is that a custom framework?
Or did you mean the IDbSet<T> interface in the System.Data.Entity namespace?
 
oo sorry it is namespace yeah
 
OK, where do you assign a value to that _dbset variable?
And what do you assign to it?
 
public Repository(IDatabaseFactory databaseFactory)
{
DatabaseFactory = databaseFactory;
_dbset = DataContext.Set<T>();
}
 
DataContext.Database.Log = Console.Write;
then run your code, check the Output window of Visual Studio, check the SQL being executed
 
5:09 PM
how should ı write this code ? into configuraiton.cs? or somewhere else?
 
How about in that constructor for Repository that you just posted?
Please note that programming is a creative profession. If you can't think for yourself, this might not be for you, have you considered that?
 
I know but I am very strange to asp.net mvc . It probably can be caused by passing asp.net mvc from classic asp directly.
I did so:
public Repository(IDatabaseFactory databaseFactory)
{
using (var context = new BlogDataContext())
{
context.Database.Log = Console.Write;
DatabaseFactory = databaseFactory;
_dbset = DataContext.Set<T>();
}
}
but I couldn't see anything related to SQL when I first debugged and then stopped my project
 
Did you try this:
DataContext.Database.Log = Console.Write;
?
 
5:27 PM
I've just tried this and when I clicked login link I got nullreferenceexception error in
protected BlogDataContext DataContext
{
get { return _dataContext ?? (_dataContext = DatabaseFactory.Get()); }
}
 
OK, Well I'm sure you'll figure out what the problem is eventually
 
5:40 PM
I think it is not about my problem because it is said that _dataContext is null and it broke out when I added codes that you remarked.

public class Repository<T> : IRepository<T> where T : class
{
private BlogDataContext _dataContext;
private readonly IDbSet<T> _dbset;
private string[] _paths;

public Repository(IDatabaseFactory databaseFactory)
{
using (var context = new BlogDataContext())
{
DataContext.Database.Log = Console.Write;
DatabaseFactory = databaseFactory;
_dbset = DataContext.Set<T>();
 
You are probably wrong. I don't know.
All I know is that

1. You've verified that the user row is in the database
2. You've verified that using SQL to retrieve the user by his email address works
3. You've verified that using your repository code using the Entity framework, doesn't
I still don't know why it doesn't work, and since you're using 10-15 minutes answering even the most basic question, then I have given up. Sorry.
 
I saw your question late because I was busy if I made you tired I'm sorry. Anyway, thanks for your help
 
Here's a tip for the future
Asking a question on Stack Overflow is an asynchronous system
You post the question, sometime in the future people start posting answers. Then, sometimes after that you read those answer, try them, post some comments, etc.
Chat, however, is instantaneous
The fact that you post your question here and ask for help means that you need to focus on the people trying to help you
If you don't want to prioritize figuring out this, why should I?
I'm going to ignore you now, you're a help vampire and I don't like those. Bye bye.
 
6:04 PM
so, i'm doing something like this:
var email = TryGetEmailFromOnePlace(param) ?? TryGetEmailFromDiffPlace(param)

but this isn't working how i expected
it uh
works when i do it this way though:
var email = TryGetEmailFromOnePlace(param);
if (string.isnullorempty(email))
email = TryGetEmailFromDiffPlace(param);
 
what's not what you were expecting?
 
well, the first method always returns null for my unit test
i dont see the difference between the two, why do they behave differently?
 
spurious overloading on the phrase 'first method' there :P
 
nvm, i think i'm tracking it down :p, helped to type it o ut
 
the first method probably returns an empty string?
ie. not really null
string.IsNullOrEmpty checks for both empty string and null, whereas ?? will only work with null.
 
6:17 PM
Anyone familiar with customizing progressbar in wpf ?
 
@AndréSilva what do you want?
 
I'm trying to make a two colored progressbar
But they alternate this two colors
Company designer screwed me up a bit
 
pic/mock?
 
Let me put it in imgur one sec
This is what I'm trying to achieve
 
6:28 PM
looks like a drawingbrush guess
 
I'm going to google it
But if you have a tutorial to give me ( only if it is reachable by your mouse pointer )
At least I know what to google now, thanks ;)
Wow got it in the first link. Thanks @JohanLarsson
 
nice, gl
 
Thanks @JohanLarsson :)
 
6:52 PM
Would anyone mind looking into a performance issue I'm having with WebAPI?
 
oh jesus, performance...
run away!
 
(I realise that's unhelpful, I kid of course. Not used it, but it sounds like this is going to become a complicated question)
 
7:10 PM
@Benjamin in what scenarios are you finding performance unacceptable?
 
@TomW 6 seconds for a website to load is not acceptable :D
 
for a single user?
are you measuring on a warm start i.e. any precompilation the application might want to do, being done first?
 
Well, I got it faster, but it's really not there yet
It's making 1 db query now instead of 21 :D Not my code initially, still takes 500 ms, needs to take no more than 100. Currently trying Azure cache.
 
I have done a lazy google and skimmed this dotnetcurry.com/showarticle.aspx?ID=948 - might this be useful for you?
 
Also, I totally missed the session locking issues since I'm not used to working with session in WebAPI
I'll read it, sure.
 
7:54 PM
Who's ready to play "rate the wtf!"?
 
8:05 PM
rofl
 
Ok, @TomW , scale of 1 to LMFAO
WebAPI controller action, calling another method that performs 21 (!) DB queries, and 14 (!) HTTP requests. Oh, to perform these HTTP requests it does a Parallel.ForEach and starts a thread pool. Also, just for fun, it uses HttpContext.Current.Session .
Oh yeah, and it's a website that's front-facing to end users. It's not intranet or anything either.
 
sounds like your office has a secret cargo cult
presumably the method you're calling isn't called UnmakeTheWorldAsync()
which is the only excuse I can think of for having that much shit being spun off
 
Has one member, new . He probably doesnt know how ORMs work or how thread pools work or how expensive making an http request in a controller is.
 
New as in new to multicellular life?
 

« first day (1282 days earlier)      last day (3665 days later) »