Posts

SingleOrDefault() Vs. FirstOrDefault() in LINQ Query

  Single() / SingleOrDefault()   First () / FirstOrDefault() Single()  - There is exactly 1 result, an exception is thrown if no result is returned or more than one result.  SingleOrDefault()  – Same as Single(), but it can handle the null value. First()  - There is at least one result, an exception is thrown if no result is returned. FirstOrDefault()  - Same as First(), but not thrown any exception or return null when there is no result. Single() asserts that one and only one element exists in the sequence. First() simply gives you the first one. When to use Use Single / SingleOrDefault() when you sure there is only one record present in database or you can say if you querying on database with help of primary key of table. When to use Developer may use First () / FirstOrDefault() anywhere,  when they required single value from collection or database.

How to call Stored Procedure in Entity Framework?

 Stored Procedure as Entity Function: Step 1. Import Stored Procedure in Entity Framework Step 2. Right-click Stored Procedure and select "Add Function Import". Step 3.  Here, we can map a returned object of our Stored Procedure. Now, we can call the Stored Procedure an entity function using the following code. The entity function returns a complex type called "EmployeeDetails". Call Stored Procedure using DbDataReader

What is difference between IEnumrable and IQueryable in c#

 In entity framework if you use filter to search the records in table like employee table then  IEnumrable  - Get the all result from query and then  filter it at client side. IQueryable - It get the filters record from if we using IQuerable and it is very efficent.

What is Difference between IEnumrable and IEnumrator in C#

 https://www.c-sharpcorner.com/UploadFile/219d4d/ienumerable-vs-ienumerator-in-C-Sharp/ Both of these interfaces help to loop through the collection. The IEnumerable interface actually uses IEnumerator. The main reason to create an IEnumerable is to make the syntax shorter and simpler. The main difference between IEnumerable and IEnumerator is an IEnumerator retains its cursor's current state. So, if you want to loop sequentially through the collection, use an IEnumerable interface else if you want to retain the cursor position and want to pass it from one function to another function then use an IEnumerator interface.

what is difference between Ienumerable and IList in c#

 IList is useful when you want to Add or remove items from the list. IList can find out the no of elements in the collection without iterating the collection. IList supports deferred execution. You use  IEnumerable when you want to loop through the items in a collection . IList is when you want to add, remove, and access the list contents out of order. IList : IList exists in System.Collections Namespace. IList is used to access an element in a specific position/index in a list. Like IEnumerable, IList is also best to query data from in-memory collections like List, Array etc. IList is useful when you want to Add or remove items from the list. IList can find out the no of elements in the collection without iterating the collection. IList supports deferred execution. IList doesn't support further filtering. IEnumerable : IEnumerable exists in System.Collections Namespace. IEnumerable can move forward only over a collection, it can’t move backward and between the items. IEnumera...

Is Entity Framework Thread Safe?

  Entity Framework DB contexts are not thread safe . If an ASP.NET Core app wishes to process requests in a multi-threaded way while using Entity Framework Core, it's important to carefully manage DbContexts so that a single context isn't used on multiple threads simultaneously.

what is ODATA with example ?

Image
OData is the Open Data Protocol. It is an open web protocol started by Microsoft to expose data using existing web technologies. This is based on Representational State Transfer (REST) full architecture. HTTP, AtomPub (similar to RSS, but specifically introduced special XML format for OData), JSON are all supported. Here, the URL is the primary operator on the data query. Example of OData Service has been used: Last (2010) football world cup (S.A), the scoring website was done using an OData Service. Why should we use an OData Service?  OData is based on the REST architecture, so we can retrieve data based on an URL. It also supports HTTP, Atom Pub as well as JSON format. It has support for any type of data source. Even you can use a custom class as a data source. No need to create a proxy service object. So, it is lightweight to use. You can create your own custom methods and expose it. Since it is lightweight, the interaction between server and client is fast. Thus, performance i...