Answer the question
In order to leave comments, you need to log in
Selecting data from two or more tables, Entity Framework?
Good day to all, please help me with this, I have been sitting for the third day and I can’t understand why in SQL Management Studio the data is selected correctly by the query, but otherwise when using EF.
It is necessary to make the display of the ad as on auto or avito, it does not matter, using images.
In general, there are a bunch of more than two related tables, these are users, ad comments, car make, model, characteristics, and images. In order not to drive a huge query there, either on Linq or on direct SQL through SQlQuery, I created a view in the database using all these tables:
The query itself to this view with a selection by declaration Id in SQLManagement:
The bottom line is that different data is returned in the PathPhoto column, I did this so that later, when returning data directly on the server in the code, select the values \u200b\u200bthat I need from this column to display on the page.
But here is a paradox or my cant, where, I have already tried everything, from working with ordinary types and Linq to direct queries, the data is returned the same, this is noticeable by the returned values of the column or already the PathPhoto property in the enumeration:
I decided to use views for the reason that the query size is really large, more than 10 columns are taken into account, and several tables, I think it is more reasonable to make it on the server, the choice fell on views. although, as I read, you can also use a function that returns the necessary data to me, although there is no experience with this yet, but the deadlines for submitting the exchange paper are already pressing. So I decided to try this. Another trick with isos, earlier I made a separate query to the Images table where I chose the images I needed by Id, but I thought that somehow it’s not very good to make two queries to one page at once ... And if EF enters the battle as I have already convinced myself. the request is simply inflated as it is unknown who and what, and what is even worse becomes nested .. when, let's say, I do this:
repository.AutoAdvertisenment.Where(p=>p.Id==idAdvert).Select(p=>new{BodyText=p.Comment,etc...});
Answer the question
In order to leave comments, you need to log in
I think that at the stage of creating a prototype, you don’t have to bother with representations, it’s better to do it in order to get a working version faster. In fact, the time to exchange an sql query is much less than other factors affecting performance when using EF (change tracking, query optimality, etc.) Anyway, if you want everything to work very quickly, EF may not be suitable ( dapper in help). Regarding your problem, without parsing the requests it is not clear what is happening there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question