Skip to main content

Posts

Showing posts with the label Insert Query in Linq to SQL

Var vs. IEnumerable in LINQ

The “ var ” is a keyword that implicitly types a variable and it is strongly typed also. The “ var ” keyword derives type from the right hand side and its scope is in the method. The “ var ” is an implicitly typed local variable. We just let the compiler determine the type i.e.             var x = 1; //Implicitly typed.             int y = 1; //Explicitly typed. For example,      var customer = ent.Customers.Where(x => x.CustId>0).ToList();     IEnumerable < Customers > customer = ent.Customers..Where(x => x.CustId>0).ToList(); In the above example, the “ var ” keyword is only syntax for a programmer.  It doesn't change the semantics at all. If we declared as “ var ” the type of customer is still IEnumerable< Customers > and both the above query will generate the same output. Actually, ...

LINQ Advantages and Disadvantages in .Net

The LINQ is stands for Language Integrated Query and it is a Microsoft .NET Framework component and use for data querying and it was released in .NET Framework 3.5 on November 19, 2007. The advantages and disadvantages for LINQ (Microsoft .Net) as give below in the details, Advantages 1.       It is quick turnaround for development. 2.       It is helps us to access any type of resource. 3.       It is a cleaner and type-safety. 4.       Lambda expressions are awesome. I am so happy to use it and I always recommended to others developers to use it. 5.       LINQ to SQL allows for RAD with database very nicely. 6.       Queries can be dynamically 7.       Declarative approach makes queries easier to understand and more compact. 8.       Extensibility and expression...

LINQ Lambda Expression query with Examples

A Lambda expression is an anonymous function that we can use to create expression tree types, delegates etc. A lambda expression is an expression on the right side of the => operator is called an expression lambda. It is also called (=>) goes to operator. Syntax:  (Input parameters) => Expirations or Statement block A Lambda expression is particularly helpful for writing LINQ query expressions. A lambda expression is powerful, shorter and suitable tool. Personally, I prefer to lambda extensions for most code writing. I am only using the statements if I am doing LINQ to SQL otherwise I am trying to emulate SQL. I find that the lambda methods flow better with code whereas the statements are visually distracting. So, here I am trying to explain gather T-SQL queries along with their LINQ queries with lambda expressions. EmpEntites empEnt = new EmpEntites();   //This is entities objects. In these entities objects, we have a table “ t...

SQL Server BETWEEN operator

The BETWEEN operator is used to select the values within a range. Syntax: -- Used of BETWEEN SELECT col1, col1 FROM Table_name WHERE col1 BETWEEN val1 AND val2; -- CREATE TABLE CREATE TABLE [dbo].[Tbl_Demo]( [ID] [ int ] IDENTITY( 1 , 1 ) NOT NULL , [Name] [ varchar ]( 500 ) NULL , [Age] [ int ] NULL , [IsActive] [ bit ] NULL , [IsDeleted] [ bit ] NULL , CONSTRAINT [PK_Tbl_Demo] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO --INSERT TABLE ROWS SET IDENTITY_INSERT [dbo].[Tbl_Demo] ON GO INSERT [dbo].[Tbl_Demo] ([ID], [Name], [Age], [IsActive], [IsDeleted]) VALUES ( 1 , N 'Anil Singh' , 30 , 1 , 0 ) GO INSERT [dbo].[Tbl_Demo] ([ID], [Name], [Age], [IsActive], [IsDeleted]) VALUES ( 2 , N 'Aradhya' , 3 , 1 , 0 ) GO INSERT [dbo].[Tbl_Demo] ([ID], [N...

Insert Query in Linq to SQL

The below code sample is used to insert register user information using asp.net c# in linq to sql . /// <summary> /// Create user profile for new user.  /// </summary> public bool RegisterUser(string FirstName, string LastName, string Email,   string password, string Country, string ZipCode, string TimeZone) {                       //TODO: We to need to run necesssary validation checks against argument.             using (var dbContext = new        BMServices_AzureEntities(DataAccess.ConnectionStringManager.ConnectionString))  {                 core_Users newUser = new core_Users();                 newUser.fir...