|
It will only get 20 records from the database but you'd have to examine the sql produced to examine how efficient it might be, especially if you have a lot of books.
|
|
|
|
|
If you change GetBooks to return IQueryable<Book> , then it will only retrieve 20 books from the database.
If it's still returning IEnumerable<Book> , then it will retrieve all books from the database, and then apply the pagination in-memory.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
i am new in EF.
so you said if i use
IEnumerable<book> then it will return all books and store in memory but if i use
IQueryable<Book> then it return 20 books from db.
public IEnumerable<book> GetBooks()
{
return _context.Books.ToList();
}
say if i wrote the getbook function like this way
public IQueryable<Book> GetBooks()
{
return _context.Books.ToList();
}
here IQueryable<book> GetBooks() return ToList() and when we are calling then we mention pagination like
IEnumerable<Book> pageOfBooks = repository.GetBooks().Skip(pageIndex * pageSize).Take(pageSize).ToList()
so .ToList() is using twice. one IQueryable<book> GetBooks() return .ToList() and other one when we are calling GetBooks()........will it have any side effect for using .ToList() ? i mean there will be any performance issue ?
please let me know and tell me does it have any performance issue if we use .ToList() twice ?.
|
|
|
|
|
Mou_kol wrote:
public IQueryable<Book> GetBooks()
{
return _context.Books.ToList();
}
First of all, that code won't compile. The List<T> class does not implement the IQueryable<T> interface.
You could make it compile by adding .AsQueryable() after .ToList() ; but that would defeat the point. The entire table would still be loaded into memory.
In order to load just a single page of books from the database, you would need to use the method I showed you previously:
public IQueryable<Book> GetBooks()
{
return _context.Books;
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
We have a form on our intranet site that employees must complete yearly.
To complete this form, employee must first enter his/her employee ID.
This ID is checked to see if this employee has completed this form before.
For instance, if this employee completed this form in the year 2016 but has not completed it in the year 2017, then his/her existing info (name, email, title) are pulled and are populated into their respective textboxes with a message that says, "Proceed"
If the employee has completed the current year of 2017, again, his/her information is pulled from employee table and populated into the textboxes so they don't have to enter those information again.
This time, the employee gets a message, "You have already completed this form"
If however, the employee has never completed this form, then the textboxes containing employee's info (name, email, title) are blank with a message, "Proceed"
So far, the only solution that seems to work is when employee has completed the form for the current year because the employee gets a message, "You have already completed the form".
How should I modify this to work in the other two situations where employee has completed previous year but has not completed the current year and employee has not never completed the form before?
Protected Sub txtEmpID_TextChanged(sender As Object, e As EventArgs) Handles txtEmpID.TextChanged
If Not String.IsNullOrEmpty(txtEmpID.Text) Then
Dim Conn As SqlConnection
'Read in connection String
Conn = New SqlConnection(ConfigurationManager.ConnectionStrings("constr").ConnectionString)
Conn.Open()
Dim cmd As New SqlCommand("select * from Employees e inner join dateDetails d on e.employeeID = d.EmployeeID where EmpID=@empID and Year(d.enterDate) >= 2016 and Year(d.enterDate)<= 2017", Conn)
cmd.Parameters.AddWithValue("@empID", txtEmpID.Text)
Dim dr As SqlDataReader = cmd.ExecuteReader()
If dr.HasRows Then
dr.Read()
checkusername.Visible = True
'imgstatus.ImageUrl = "images/NotAvailable.jpg"
lblStatus.Text = "Please verify your information for accuracy. Then complete rest of the form."
lblStatus.ForeColor = System.Drawing.Color.Red
System.Threading.Thread.Sleep(100)
txteName.Text = dr("employeeName").ToString()
txttitle.Text = dr("empTitle").ToString()
txtemail.Text = dr("email").ToString()
txtEmpID.Text = dr("empID").ToString()
Else
dr.Read()
checkusername.Visible = True
'imgstatus.ImageUrl = "images/Icon_Available.gif"
lblStatus.Text = "Proceed"
lblStatus.ForeColor = System.Drawing.Color.Red
System.Threading.Thread.Sleep(100)
txteName.Text = dr("employeeName").ToString()
txttitle.Text = dr("empTitle").ToString()
txtemail.Text = dr("email").ToString()
txtEmpID.Text = dr("empID").ToString()
End If
Else
checkusername.Visible = False
End If
End Sub
|
|
|
|
|
I would imagine that you have a column in the database design that represents the "FORM_YEAR" and "FORM_STATUS"
When the form is completed the status of the "FORM_STATUS" changes to completed or true and the FORM_YEAR would be updated to 2018
If it ain't broke don't fix it
|
|
|
|
|
HI,
our office use VSS as source control. just come to know that VSTS is free for five user and our team is very small with 5 devs.
i have never use VSTS. so i have few questions. please answer point wise and with detail along with images if possible.
1) how to create a account for VSTS?
2) how to upload our local project exist in my pc to VSTS
3) how could i send invitation to other 4 developer in our team as a result they can clone our uploaded project in their own pc and start working ?
i got one link http://www.codeease.com/add-local-project-to-visual-studio-online.html which is showing how to Add Local Project to Visual Studio Online GIT but i need to know how to add to online TFS.
please guide me with sample images and details instruction. thanks
|
|
|
|
|
|
Not sure where to place this post.
I took the update a couple of days ago for VS2017 V15.5.0
My VS2017 was working fine for over a year and this update changed something, and I can't pinpoint it.
So I work on the old style MVC projects, where you have a Views, Controllers, etc. and the views went black and white, no intelisense.
Then on the create project, it no longer shows under website, MVC. It only shows Core.
The VS2017 installation always bombs on a DISM file called netfxextension-aspnet45 and says it doesn't exist.
I'm not sure if my VS2017 is broke or if my Win10 is broken.
Just wanted to see if anyone else has ran into this and a point in the right direction to fix it.
If it ain't broke don't fix it
|
|
|
|
|
Sounds like Visual Studio's broken. Try the "repair" option in the installer. If that doesn't work, try the "modify" option and verify that the relevant parts are installed.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I've done that like 5 times yesterday.
I think that the templates I'm looking for can be downloaded, in which I tried yesterday. But it failed to install because netfx4extendable-aspnet45 count not be located.
So today I will focus on finding that feature and install it.
I think the Win10 team and VS team have a conflict here.
If it ain't broke don't fix it
|
|
|
|
|
I finally fixed it and it works great now.
It was a Windows 10 problem. Guess the last big update broke it.
So I had to create a installation disk and do sort of a clean install.
Now my VS2017 15.5.1 works and all the project templates are there now.
And the Views have intellisense and color now. Go Figure, spent 2 days thinking it was VS2017
If it ain't broke don't fix it
|
|
|
|
|
Hi
I've created my own rest service. For test purpose i've used Soap UI for testing of the service.
Now i try to consume this service in a webform. On the controller i can see that it has processed a call, so the service request gets through to my service. By debugging i can see that the rest server gets the data from the database.
When i try consuming the service in a asp.net 4.5 webform it hangs...
it just hangs on this statement
var response = await client.GetAsync("ServerConfig");
My request code looks like this:
private WebApiClientOptions options = new WebApiClientOptions("http://localhost:54990/api", "ServerConfig");
protected void Page_Load(object sender, EventArgs e)
{
List<ServerConfig> list = null;
list = this.Index().Result;
}
public async Task<List<ServerConfig>> Index()
{
List<ServerConfig> list = null;
using (WebApiClient<ServerConfig> client = new WebApiClient<ServerConfig>(options))
{
var liste = await client.GetManyAsync();
}
return list;
}
i hope there is a clever person WHO can help a complete newbiee
Yours
Wilco
|
|
|
|
|
You have a classic deadlock.
await signs the rest of the method up to run as a continuation when the awaited task completes. By default, it will be scheduled to run in the same execution context as the caller.
Calling .Result on a task blocks the current thread until the task has completed. But the task can't complete until the continuation has run on the current execution context. Which can't happen until the current thread is un-blocked. Which can't happen until the task has completed.
The quick-and-dirty fix is to add .ConfigureAwait(false) to your awaited tasks. That allows the continuation to run on a different thread:
var liste = await client.GetManyAsync().ConfigureAwait(false);
The best solution would be to move your work to a proper task-returning async method, and register that as an async task:
private void Page_Load(object sender, EventArgs e)
{
RegisterAsyncTask(new PageAsyncTask(LoadAsync));
}
private async Task LoadAsync()
{
List<ServerConfig> list = await Index();
...
}
Using Asynchronous Methods in ASP.NET 4.5[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks
I got the registerAsyncTask to Work
Yours
Wilco
|
|
|
|
|
I have a process that populates a pdf template based on user input. Can the system handle multiple users filling out web form and populate pdf template and save the populate pdf into a different directory.
I am using Itextsharp. We are using one pdf template to create the pdfs. Should I put the PDF template in the database and load it into my program as a blob?
Thanks,
mjc
|
|
|
|
|
Michael Clinton wrote: Can the system handle multiple users filling out web form and populate pdf template and save the populate pdf into a different directory. Almost certainly, although it's hard to tell without seeing your code.
I do something very similar using PDFSharp without any problems. So long as you're using FileShare.Read when you open the file, other threads and processes should be able to read it at the same time.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Greetings again experts,
I have seven gridview controls, Gridview1 through Gridview7.
For now, I am posting below the code for two of the seven gridview controls.
<asp:gridview ID="Gridview1" gridlines="None" runat="server" ShowFooter="true" AutoGenerateColumns="false" onrowdatabound="Gridview1_RowDataBound" OnRowDeleting="Gridview1_RowDeleting">
<Columns>
<asp:BoundField DataField="RowNumber" Visible="false" HeaderText="Row Number" />
<asp:TemplateField HeaderText="Name">
<headerstyle horizontalalign="Left" />
<ItemTemplate>
<asp:TextBox ID="txtsourcename" placeholder="Name..." runat="server" style="width:250px;" class="form-control"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address">
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="txtsourceaddress" placeholder="Address..." runat="server" style="width:250px;" class="form-control"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Income">
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="txtsourceincome" placeholder="Income...(example: 1000)" runat="server" style="width:250px;" class="form-control txtsourceincome numeric"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Button ID="ButtonAdd" runat="server" Text="Add"
onclick="ButtonAdd_Click" CssClass="grvAddButton" OnClientClick="return ValidateEmptyValue();" />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True"><ControlStyle CssClass="grvDelButton" /></asp:CommandField>
</Columns>
</asp:gridview>
<span style="font-weight:bold;font-size:18px;color:#000000;">Name and address of income source of spouse greater than $1,000.00 (No comma (,) or period(.); Example 1000)</span><br /><br />
<asp:gridview ID="Gridview1" GridLines="None" runat="server" ShowFooter="true" AutoGenerateColumns="false" onrowdatabound="gGridview1_RowDataBound" OnRowDeleting="Gridview1_RowDeleting">
<Columns>
<asp:BoundField DataField="SpouseNumber" Visible="false" HeaderText="Row Number" />
<asp:TemplateField HeaderText="Name">
<headerstyle horizontalalign="Left" />
<ItemTemplate>
<asp:TextBox ID="txtspousename" placeholder="Name..." runat="server" style="width:250px;" class="form-control"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address">
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="txtspouseaddress" placeholder="Address..." runat="server" style="width:250px;" class="form-control"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Income">
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="txtspouseincome" placeholder="Income...(example: 1000)" runat="server" style="width:250px;" class="form-control txtsourceincome numeric"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Button ID="ButtonAdd2" runat="server" Text="Add"
onclick="ButtonAdd2_Click" CssClass="grvAddButton" OnClientClick="return ValidateSPEmptyValue();" />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True"><ControlStyle CssClass="grvDelButton" /></asp:CommandField>
</Columns>
</asp:gridview>
Our requirement is that each gridview control must have a checkbox next to it.
Users are asked to fill all the textboxes in each gridview control.
However, if user does not see the need to complete the textboxes in any particular gridview control, then we need to have user check a box next to each gridview control to disable that gridview control.
If any gridview is not completed and a box is not checked, an error needs to be raised and user should not be allowed to submit the form.
Does anyone know to do this?
Thanks in advance
|
|
|
|
|
It should just be as simple as a checkbox with auto postback, that triggers code wired to an event handler for the checkbox
and then say Gridview1.Disable
I've never done it personally with a gridview, but the control should have the disable feature, or visible and just make it disappear.
If it ain't broke don't fix it
|
|
|
|
|
First of all, thanks a lot for your response.
If you have not done it with Gridview, especially when you have to make sure that user cannot submit without either completing the textboxes for a particular view or checking a box next to a particular gridview, then you can't it is simple.
|
|
|
|
|
All the .Net stock controls for WebForms follow the same format. I've done it in code behind using server controls in pure code, but have never done it in code behind using the control on a web form. But it should be the same thing.
If it ain't broke don't fix it
|
|
|
|
|
I have done it too.
It is much different with Gridview, Repeater, etc.
That's why I am struggling with it.
|
|
|
|
|
I have successfully implemented code which uses ManagementObjectSearcher to query and return the status of printers on one of our servers.
Now what I would like to do is use this code from an ASP.net web page so that my user community can view the status of those same printers. The problem is that the account that the webserver executes as does not have the appropriate permissions to retrieve the data.
My research seems to point to a method to get the data where I would pass credentials while executing the query.
The building blocks are:
1) Dim Credentials As New CimCredential(PasswordAuthenticationMechanism.Default, domain, username, securepassword)
2) Session = CimSession.Create(computer, SessionOptions)
3) session.QueryInstances("@root\cimv2", "WQL", "SELECT * FROM Win32_Printer")
However, I can't seem to find the proper reference to the Microsoft.Management.Infrastructure.dll
My development environment is VS2015 / Win10 and I plan to deploy the web application to a 7.5 IIS server.
Can someone help me find the correct dll location ?
Am I approaching this problem correctly ?
Thanks.
|
|
|
|
|
According to this thread[^], it should be in:
C:\Program Files (x86)\Reference Assemblies\Microsoft\WMI\v1.0
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yea, I saw that reference too. Unfortunately, that path does not exist on my Win10 machine.
Am I missing a feature?
|
|
|
|