Using generic type to standardized data flow.
have multiple table needed to be inserted or deleted, Have to use Transaction.
Check Null is super important,both at back end or database.
when SaveChange throws an error. It is because we don’t set the columns for the table to be not null。
Definitely use enum to store constant variable
navigation property make developer’s life much easier because you don’t need to worry about the Joining.
If you want to create the instance of dbcontext, remember to use “using” to release the garbage in memory. It can clean up the memory automatically
soft delete. We will only need to set the active to false instead of deleting it all
set the default value for parameters of a function by using int num = 0.
use factory or Interface to decouple between each layers.
Json(result.Data, JsonRequestBehavior.AllowGet) standard way of passing data to front-end in controller.
If you want to have the id for the record which is just added with ORM-ef, get it after DB.SAVACHANGE().
EF lazy loading (when it is transferred to list. It then generates SQL query)
Don’t use generate SQL in foreach loop, it is disaster.
naming convention is important. Camel case is always good.
Trying to use reflector to read the source code. It will help you with the understanding of CLR.
put partial view into modal is a good idea. use partial view to display a table which needed to updated, your page would not be refreshed.
The output in the console would not be 21 or 20. Because girl has its own execution context. console.log(x) would not look for the global x.
When it executes the girl function. x is actually hoisted in the context of girl function but it is after console.log. So, the answer to this code would be undefined.
1. All record with null will not be a part of count.
2. Check if this value is null. Dont use null==null, use null is null.
3. The difference between IN and EXIST:
- Works on List result set
- Doesn’t work on subqueries resulting in Virtual tables with multiple columns
- Compares every value in the result list
- Performance is comparatively SLOW for larger resultset of subquery
- Works on Virtual tables
- Is used with co-related queries
- Exits comparison when match is found
- Performance is comparatively FAST for larger resultset of subquery
4. What is Union and Union ALL
Union merges the contents of two structurally-compatible tables into a single combined table. The difference between Union and Union ALL is that Union will omit duplicate records whereas Union ALL will include duplicate records.
It is important to note that the performance of Union ALL will typically be better than Union , since Union requires the server to do the additional work of removing any duplicates. So, in cases where is is certain that there will not be any duplicates, or where having duplicates is not a problem, use of Union ALL would be recommended for performance reasons.
String Reference type method:
bool b = a.Contains (‘x’); / / Contains () to determine whether this word contain certain string. return bool value type.
bool b = a.StartsWith (” x “); // StartsWith () check if the string starts with the character x. return Boolean value type.
bool b = a.EndsWith (” x “); // EndsWith () check if the string ends with the character x. return Boolean value type.
bool b = a.Equals ( “xx”); // Equals () to determine whether two strings are the same.
int b = a.IndexOf (“x”); // IndexOf () return the index of the char in the string.
int b = a.LastIndexOf (“x”) ; // LastIndexOF () return the last index of char in the string.
string b = a.Insert(int, “x”); insert the char at the index of you want.
bool b = string.IsNullOrEmpty (x); // IsNullOrEmpty () will check whether the string is null or empty. It will return a Boolean value.
string b=a.Remove(1,10); //Remove() delete the string from index 1 to 10 and return the rest to string b.
string  strs = a.Split (‘x’); // split()
string strs = a.Substring (int, int); / / Substring () is also used to split the string with the index starting with first parameter and ending with the second parameter.(return string)
string str = strs.ToLower() // The ToLower () convert uppercase to lowercase
string str = strs.ToUpper = (); // the ToUpper () convert lowercase to uppercase.
string str = strs.Trim (); // Trim () clears the space on both sides of the string
This is stored procedure with high performance
create PROCEDURE [dbo].[GetPageDataOut]
@tn nvarchar(30),–the name of the table
@idn nvarchar(20),–the name of primary key for the table
@pi int = 1,–current index of the page
@ps int = 7,–size of the page
@rc int output,–total row (out parameter)
@pc int output—total page (out parameter)
DECLARE @sql NVARCHAR(225),@sqlCount NVARCHAR(225)
SET @sqlCount = ‘SELECT @rc=COUNT([‘+@idn+’]),@pc=CEILING((COUNT(‘+@idn+’)+0.0)/’+ CAST(@ps AS VARCHAR)+’) FROM ‘ + @tn
EXEC SP_EXECUTESQL @sqlCount,N’@rc INT OUTPUT,@pc INT OUTPUT’,@rc OUTPUT,@pc OUTPUT
IF @pi = 1
SET @sql=’SELECT TOP ‘+str(@ps) +’ * FROM ‘+@tn
SET NOCOUNT ON
DECLARE @PageLowerBound INT,@StartID INT
SET @PageLowerBound = @ps * (@pi-1)
SET ROWCOUNT @PageLowerBound
SET @sql=N’SELECT @StartID = [‘+@idn+’] FROM ‘+@tn
EXEC sp_executesql @sql,N’@StartID int output’,@StartID output
SET ROWCOUNT 0
SET @sql=’SELECT TOP ‘+str(@ps) +’ * FROM ‘+@tn+’ WHERE [‘+@idn+’]>’+ str(@StartID)
SET NOCOUNT OFF
declare @rc int,@pc int
exec GetPageDataOut ‘Ams_Area’,’ar_id’,2,15,@rc output,@pc output
So applying this pattern to your code you may have multiple modules and you have the control over what you want to make public and what to keep private. Besides your code will be more organized therefore easy to maintain.
Q1: What is ASP.NET? What is the main difference between ASP and ASP.NET?
A: ASP.NET is Microsoft’s server-side technology for creating dynamic and user-friendly Web applications, Web sites and Web services. You can create ASP.NET applications in most of the .NET compatible languages, such as VB, C#, and J#. The ASP.NET compiles the Web pages and provides much better performance than scripting languages. The main difference between ASP and ASP.NET is that ASP is interpreted; whereas, ASP.NET is compiled.
Q2: What is the concept of Postback in ASP.NET? How can we identify that the Page is Post Back?
A: A postback is a request sent from a client to the server from the same page where a user is already working. It’s basically posting a complete page back to server (i.e. sending all of its data) on the same page. So, the whole page is refreshed.
Page object has an “IsPostBack” property, which can be checked to know that is the page posted back.
Q3: What is an assembly?
A: An assembly is one of the elements of a .NET application and is termed as a primary unit of all .NET applications. This assembly can be either a DLL or an executable file.
Q4: What is the difference between method overriding and method overloading?
A: Overriding involves the creation of two or more methods with the same name and same signature in different classes.
Overloading is a concept of using a method at different places with the same name and different signatures within the same class.
Q5: What is constructor and why we use constructor?
A: Constructor is a special method of a class, which is called automatically when the instance of a class is created. It is created with the same name as the class and initializes all class members, whenever you access the class.
The main features of a constructor are as follows:
- Constructors do not have any return type
- Constructors are always public
- It is not mandatory to declare a constructor; it is invoked automatically by .NET Framework
Q6: What is a delegate and multicast delegates?
A: A delegate is similar to a class, used for storing the reference to a method and invoking that method at runtime, if required. Some of the examples of delegates are type-safe functions, pointers or callbacks.
A delegate object is to hold references of and invoke multiple methods. Such delegate objects are called multicast delegates or combinable delegates.
Q7: What is a namespace?
A: Namespace is considered as a container that contains a functionally related group of classes and other types.
Q8: Can you declare a private class in a namespace?
A: The classes in a namespace are internal, by default. However, you can explicitly declare them as public only and not as private, protected, or protected internal.
Q9: What is garbage collection?
A: Garbage collection prevents memory leaks during execution of programs. Garbage collection is a low-priority process that manages the allocation and de-allocation of memory for your application. If GC finds any object that is no longer used by the application, it frees up the memory from that object.
Q10: Difference between Response.Redirect and Server.Transfer?
A: In case of Response.Redirect, a new request is generated from client-side for redirected page. It’s a kind of additional round trip. As a new request is generated from the client, the new URL is visible to users in the browser after redirection.
While in the case of Server.Transfer, a request is transferred from one page to another without making a round trip from the client. For the end user, the URL remains the same in the browser even after transferring to another page.
Q11: Briefly explain the use of Global.asax.
A: Global.asax is basically ASP.NET Application file. It’s a place to write code for Application-level events such as Application start, Application end, Session start and end, Application error etc. raised by ASP.NET.