Friday, June 19, 2015

LINQ & Entity Frame work

1.Concatenating the first name and last name?

Just add another property in your View and concatenate FirstName and LastName as a read only property , Somthing like this :
public string FullName 
{
    get { return FirstName + " " +LastName ;}
}

return (from c in db.Doctors select new Doctor { FullName = c.FirstName + " " + c.LastName, DoctorId = c.DoctorId }) .ToList<Doctor>(); // or just .ToList();

public class DisplayDoctor { public string FullName { get; set; } public int DoctorId { get; set; } } return (from c in db.Doctors select new DisplayDoctor { FullName = c.FirstName + " " + c.LastName, DoctorId = c.DoctorId }) .ToList<DisplayDoctor>(); // or just .ToList();

2,Left outer join in LINQ?

//left join


var result = from c in db.Customers

join o in db.Orders on c.CustomerId equals o.CustomerId into gj

from sub in gj.DefaultIfEmpty()

select new { Quantity = c.CustomerName, pet=(sub==null ? 0: sub.OrderId) };





ruleSets = (from rs in db.RuleSets
join brs in db.BatchRuleSets on rs.ID equals brs.RuleSetID into j1 
from jbrs in j1.DefaultIfEmpty() 
join b in db.Batches on jbrs.BatchID equals b.id into j2 from jb in j2.DefaultIfEmpty() where !clientId.HasValue || jb.ClientID == clientId.Value where !batchId.HasValue || jbrs.BatchID == batchId.Value select new { rs.ID, rs.Description, rs.IsActive, rs.CreatedDate, rs.EffectiveDate, rs.ExpirationDate, BatchName = jb.FileName, jb.ClientID }).ToList().Select(x => new { x.ID, x.Description, x.IsActive, x.CreatedDate, x.EffectiveDate, x.ExpirationDate, x.BatchName, ClientName = GetClientName(x.ClientID)});

3.Inner Join?


//inner join

//var result = from c in db.Customers


// join o in db.Orders on c.CustomerId equals o.CustomerId


// select new { Quantity = c.CustomerName, order1=o.OrderId };





 class Program { static AccountContextDataContext aContext = new AccountContextDataContext(@"Data Source=;Initial Catalog=;Integrated Security=True"); static LoanContextDataContext lContext = new LoanContextDataContext(@"Data Source=;Initial Catalog=;Integrated Security=True"); static void Main() { var query = from a in aContext.ACCOUNTs join app in aContext.APPLICATIONs on a.GUID_ACCOUNT_ID equals app.GUID_ACCOUNT where app.GUID_APPLICATION.ToString() == "24551D72-D4C2-428B-84BA-5837A25D8CF6" select GetLoans(app.GUID_APPLICATION); IEnumerable<LOAN> loan = query.First(); foreach (LOAN enumerable in loan) { Console.WriteLine(enumerable.GUID_LOAN); } Console.ReadLine(); } private static IEnumerable<LOAN> GetLoans(Guid applicationGuid) { return (from l in lContext.LOANs where l.GUID_APPLICATION == applicationGuid select l).AsQueryable(); } }


4. Lazy loading in Entity framework?
Lazy loading means delaying the loading of related data until you specifically request it. For example, Student class contains StudentAddress as complex property. So context first loads all the students from the database then it will load address of particular student when we access StudentAddress property as below.
Rules for lazy loading:

  1. context.Configuration.ProxyCreationEnabled should be true.

  1. context.Configuration.LazyLoadingEnabled should be true.

  1. Complex property should be defined as virtual. Context will not do lazy loading if the property is not define as virtual.
http://www.codeproject.com/Articles/652556/Can-you-explain-Lazy-Loading

Remove the Order from consturctor.

public List
    customer cust=new customer()
    foreach(Order o1 in orders)
    {
    console.writeline(o1.ordernumber);//lazy loading calls now
    }


    5.Calling stored procedure in Entity framework?

    Right-click Stored Procedure and select "Add Function Import".
    return item is complex type

    using (Entities context = new Entities())
    {
    IEnumerable<EmployeeDetails> empDetails = context.GetEmployeeData();
    }

    2nd option suing exec

    // using DBContext (EF 4.1 and above)using (Entities context = new Entities())
    {
    IEnumerable<EmployeeDetails> empDetails = context. Database.SqlQuery
    < EmployeeDetails >("exec GetEmployeeData ", null).ToList();
    }
    3rd option
3. Call Stored Procedure using DbDataReader

We can also retrieve data or call a Stored Procedure using a SQL Connection Command and DbDataReader. The Object Context has a translate method that translates the entity data from DbDataReader into the requested type object. This method enables us to execute a standard ADO.Net query against a data source and return data rows into entity objects. Using the following code we can call a Stored Procedure and retrieve data in entity form.
using (Entities context = new Entities())
{
string ConnectionString = (context.Connection as EntityConnection).StoreConnection.ConnectionString;
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(ConnectionString);
builder.ConnectTimeout = 2500;
SqlConnection con = new SqlConnection(builder.ConnectionString);
System.Data.Common.DbDataReader sqlReader;
con.Open();
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "GetEmployeeData";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandTimeout = 0;
sqlReader = (System.Data.Common.DbDataReader)cmd.ExecuteReader();
IEnumerable<EmployeeDetail> empDetails = context.Translate<EmployeeDetail>(sqlReader).ToList();
}
}

Stored procedure in EF?

http://www.entityframeworktutorial.net/stored-procedure-in-entity-framework.aspx

6.Multiple Databases in Entity framework?

7.Entity framework advantages ?
Maintain the versioning.

8. How to enable migration EF?
Enable-Migrations -ContextTypeName AdvantureworksContext
pm>Add-Migration Initial -ignorechanges
pm>update-database

9. EDM file consist of?

SSDL Content,CSDL and C -S mapping content
i.storage model
ii.Conceptual Model
iii.Mappings

a.Entity Container
b.Entity Set
c.Entity Type
d.Association Set
e.Object context

10.Eagar loading?
Eager loading is achieved using the Include method of IQueryable.


 using (var context = new SchoolDBEntities())
        {
            var res = (from s in context.Students.Include("Standard")
                        where s.StudentName == "Student1"
                        select s).FirstOrDefault();
        }
Student table and Standard table

11.What is entity framework?
Writing and managing ADO.Net code for data access is a tedious and monotonous job. Microsoft has provided an O/RM framework called "Entity Framework" to automate database related activities for your application.
 

Entity framework is an Object/Relational Mapping (O/RM) framework. It is an enhancement to ADO.NET that gives developers an automated mechanism for accessing & storing the data in the database.

Thursday, March 12, 2015

Scnario based questions

1. 10 resources keep on logging and checking any file is came into system then he can download and update the system. We need to automate and provide architecture.

batch program and scheduled

2.password encrypt using SHA1, MD5 using round rabin.
design the object, send the server , password and sha1.

3.One employee resign how to intimate the payroll? 

Tuesday, July 1, 2014

Project Manager

1. Cost estimation
2.Scope Management
3.Knowledge key areas.
4.Conflict Management
5.Who will you find out stake holders?
Stake holder analysis,meetings and expert judgement
6.Developer effort estimation.
7.Risk Management?
8.What are the achievements?
9.Roles and responsibilities?
10.What are the project metrics you are following?

Friday, June 27, 2014

VB.Net

1.What is Auto Event wire up ?
Asp.Net pages automatically bind page events to methods that have the name Page_events. This is automatically binding is configured by the Auto Event wireup attribute in the @ page directive, which is set to true by default in C3. If you set Auto event wire up to false the page doesn't automatically search for methods that use the page_events
Auto Event wire up=false and c# auto event wire up=true.

2.What is the process?
Process is set of tasks running application.

3.Tell type of assemblies?
1.Shared, 2.Private 3.Satellite assembly. 

 

Saturday, July 13, 2013

JQuery

http://www.codeproject.com/Articles/618484/Latest-jQuery-interview-questions-and-answers

1.Replace?
$( "div.third" ).replaceWith( $( ".first" ) );
2.How to maintain the sessions in JQuery?
$.session.set("compareLeftContent","value"); alert($.session.get("compareLeftContent"));
2. Jquery vs AngularJS

RestFul API will not support Jquery
MVC pattern support. AngularJS
Twoway data binding
Form validation
Localization

MCV3 Interview questions


http://www.dotnet-tricks.com/Home/MVCInterviewBook

http://www.codeproject.com/Articles/556995/Model-view-controller-MVC-Interview-questions-and#How_to_implement_windows_authentication_for_MVC

http://www.dotnet-tricks.com/Tutorial/mvc/LYHK270114-Detailed-ASP.NET-MVC-Pipeline.html

http://www.codeproject.com/Articles/741228/MVC-Application-Lifecycle

1.Action filters?



  • OutputCache – This action filter caches the output of a controller action for a specified amount of time.
  • HandleError – This action filter handles errors raised when a controller action executes.
  • Authorize – This action filter enables you to restrict access to a particular user or role.

  • The Different Types of Filters

    The ASP.NET MVC framework supports four different types of filters:
    1. Authorization filters – Implements the IAuthorizationFilter attribute.
    2. Action filters – Implements the IActionFilter attribute.
    3. Result filters(response fileters) – Implements the IResultFilter attribute.
    4. Exception filters – Implements the IExceptionFilter attribute.
    2.Advantages of Unity?

    1. It provides simplified object creation, especially for hierarchical object structures and dependencies, which simplifies application code. It contains a mechanism for building (or assembling) instances of objects, which may contain other dependent object instances.
    2. It supports abstraction of requirements; this allows developers to specify dependencies at run time or in configuration and simplify the management of cross-cutting concerns.
    3. It increases flexibility by deferring component configuration to the container. It also supports a hierarchy for containers.
    4. It has a service location capability, which is useful in many scenarios where an application makes repeated use of components that decouple and centralize functionality.
    5. It allows clients to store or cache the container. This is especially useful in ASP.NET Web applications where developers can persist the container in the ASP.NET session or application.
    6. It has an interception capability, which allows developers to add functionality to existing components by creating and using handlers that are executed before a method or property call reaches the target component, and again as the calls returns.
    7. It can read configuration information from standard configuration systems, such as XML files, and use it to configure the container.
    8. It makes no demands on the object class definition. There is no requirement to apply attributes to classes (except when using property or method call injection), and there are no limitations on the class declaration.
    9. It supports custom container extensions that you can implement; for example, you can implement methods to allow additional object construction and container features, such as caching.
    10. It allows architects and developers to more easily implement common design patterns often found in modern applications.


    3.Life cycle of MVC3?




    Request -->Routing --> Handler -->Controller --> Action --> View --> Response

    4.Http module?

    Http handler in asp.net, mvc handler in mvc
    ASP.NET MVC has action filters, while ASP.NET has HTTP modules.

    5.How to deploy the MVC application?

    http://forums.asp.net/t/1748670.aspx?Deploy+MVC+3+application+into+IIS+7

    6.

    Explain attribute based routing in MVC?

    This is a feature introduced in MVC 5. By using the "Route" attribute we can define the URL structure. For example in the below code we have decorated the "GotoAbout" action with the route attribute. The route attribute says that the "GotoAbout" can be invoked using the URL structure "Users/about".
    public class HomeController : Controller
    {
           [Route("Users/about")]
           public ActionResult GotoAbout()
           {
               return View();
           }
    }

    7.

    How can we maintain sessions in MVC?

    Sessions can be maintained in MVC by three ways: tempdata, viewdata, and viewbag.

    8 Restful services?
    RESTful architecture use HTTP for all CRUD operations like (Read/Create/Update/Delete) using simple HTTP verbs like (GET, POST, PUT, and DELETE).It’s simple as well as lightweight. 

    9. difference between mvc3,mvc4 and mvc5?


    10. asp.net and mvc3

    Asp.Net Web Forms
    Asp.Net MVC

    Asp.Net Web Form follow a traditional event driven development model.
    Asp.Net MVC is a lightweight and follow MVC (Model, View, Controller) pattern based development model.

    Asp.Net Web Form has server controls.
    Asp.Net MVC has html helpers.

    Asp.Net Web Form supports view state for state management at client side.
    Asp.Net MVC does not support view state.

    Asp.Net Web Form has file-based URLs means file name exist in the URLs must have its physically existence.
    Asp.Net MVC has route-based URLs means URLs are divided into controllers and actions and moreover it is based on controller not on physical file.

    Asp.Net Web Form follows Web Forms Syntax
    Asp.Net MVC follow customizable syntax (Razor as default)

    In Asp.Net Web Form, Web Forms(ASPX) i.e. views are tightly coupled to Code behind(ASPX.CS) i.e. logic.
    In Asp.Net MVC, Views and logic are kept separately.

    Asp.Net Web Form has Master Pages for consistent look and feels.
    Asp.Net MVC has Layouts for consistent look and feels.

    Asp.Net Web Form has User Controls for code re-usability.
    Asp.Net MVC has Partial Views for code re-usability.

    Asp.Net Web Form has built-in data controls and best for rapid development with powerful data access.
    Asp.Net MVC is lightweight, provide full control over markup and support many features that allow fast & agile development. Hence it is best for developing interactive web application with latest web standards.

    Asp.Net Web Form is not Open Source.
    Asp.Net Web MVC is an Open Source.

    11.Maximum how many parameters we can pass in mvc?
    I suspect that there is no limit on the number of arguments - your main limitation wouild be the maximum HTML request/header lengths imposed by both the browser and server.

    we can change path segment length setting UrlSegmentMaxLength in regedit.

    12. Views and forms in MVC?
    Each view having multiple forms.
    http://stackoverflow.com/questions/15788806/asp-net-mvc-4-multiple-post-via-different-forms

     13 MVC attributes?

    14.Request processing?
    Incoming request->Parse URL->find matching Route->Process request

    15. Server side binding dropdownlist in MVC?

    http://www.c-sharpcorner.com/UploadFile/3d39b4/dropdownlist-in-Asp-Net-mvc/


    @Html.DropDownList("Action", PathToController.GetUsers())
    then on the controller where you want to put this method
    public static List<SelectListItem> GetUsers(){
        List<SelectListItem> ls = new List<SelectListItem>();
        var result = //database call here
        foreach(var temp in result){
            ls.Add(new SelectListItem() { Text = temp.Name, Value = temp.ID });
        }
        return ls;
    }
    16. Overriding the Routing?
     
    public class HomeController : Controller
    {
           [Route("Users/about")]
           public ActionResult Aboutgo()
           {
               ViewBag.Message = "You successfully reached USERS/About route";
               return View();
           }
    }
    17.How many forms we can use in view of mvc?
    Yes we can have multiple forms inside one view.
    
    
    18.What is model ,view and control?
    MVC: View renders the data from model in response to the request made to the model by controlled events made by user interaction.
    Controller :Controller responds to events to command model and view to  change. User interaction triggers the events to change the model, which in turn calls some methods of model to update its state to notify other registered views to refresh their display
    Model is accessible by both controller and view
    Model can be used to pass data from controller to view
    View can be use model to display the data in page.
    View is an ASPX page without having code behind file.
    A request to view can be made only from a controller’s action method
    Controller can access  and use model class to pass data to views
    19.MVC 3 life cycle.
    20.What does Model, View and Controller represent in an MVC application?
    Model: Model represents the application data domain. In short the applications business logic is contained with in the model.
    View: Views represent the user interface, with which the end users interact. In short the all the user interface logic is contained with in the UI.
    Controller: Controller is the component that responds to user actions. Based on the user actions, the respective controller, work with the model, and selects a view to render that displays the user interface. The user input logic is contained with in the controller.
    21.Modal Binding?
    MVC Modal binding allows you to map http request data with a modal.
    MVC runtime uses default model binder to build the parameters
    Model binding implicitely goes to work when you have an action parameter
    Model binding can be explicitely invoke using updatemodel and tryupdatemodel methods