logo
down
shadow

Sql Transcation Query to Linq Query in Wcf Rest Service


Sql Transcation Query to Linq Query in Wcf Rest Service

By : Kaleb
Date : November 22 2020, 03:01 PM
This might help you I am converting one sql Transcation query to Linq query . I have done little bit and i am trying to write rest of the linq query but i am confused .. , Inside your using you should issue another query like this:
code :
var rewardAccount = ctx.Reward_Account_Details
    .Where(r => r.Account_Number = moneyTransfer.Sender_Account_No)
    .FirstOrDefault();

rewardAccount.Account_Balance -= moneyTransfer.Ammount;
public bool MoneyTranfer(MoneyTransfer mopneyTransfer)
{
    int i = Convert.ToInt32(mopneyTransfer.Amount);
    int j = Convert.ToInt32(mopneyTransfer.Amount1);

    try
    {
        using (HalifaxDatabaseEntities ctx = new HalifaxDatabaseEntities())
        {
            var foundAccount = (from a in ctx.Current_Account_Details where a.Account_Number.Equals(mopneyTransfer.Sender_Account_No)
                                select a).Distinct().FirstOrDefault();

            var acctDetails = (from a in ctx.Current_Account_Details
                               where a.Account_Number.Equals(mopneyTransfer.Sender_Account_No)
                               select a).Distinct().FirstOrDefault();

            if(acctDetails == null)
                return false;

            var rewardAccount = ctx.Reward_Account_Details
                .Where(r => r.Account_Number = moneyTransfer.Sender_Account_No)
                .FirstOrDefault();

            rewardAccount.Account_Balance -= moneyTransfer.Ammount;

            ctx.SaveChanges();

            return true;
        }
    }
    catch(Exception)
    {
        //Maybe log it.
    }
    return false;
}


Share : facebook icon twitter icon
How to design angular service class for REST service with optional query params

How to design angular service class for REST service with optional query params


By : ggly
Date : March 29 2020, 07:55 AM
To fix the issue you can do The url building ( baseUrl + "/my-suffix" ) is not of bad design imho.
The query parameter building is. $http.get can take a map for this :
code :
$http.get(myUrl, { params : myParamMap })
$http.get(myUrl, { params : { valid : true, departmentId : "myDepId" } });
var STUDENT_URL = ENV_CONSTANTS.baseUrl+'/students';
$http.get(STUDENT_URL, { params : myParams });
function performStudentCall(paramMap) {
    return $http.get(STUDENT_URL, { params : paramMap });
}
function getValidStudentByDepartment (departmentId) {
    return performStudentCall({ valid : true, departmentId : departmentId });
}
EntityFramework LINQ query count fails but query returns result. How to optimize LINQ query?

EntityFramework LINQ query count fails but query returns result. How to optimize LINQ query?


By : Milly
Date : March 29 2020, 07:55 AM
This might help you Not quite sure that's the problem, but at least let try to eliminate the potential effect of the so called Parameter Sniffing Problem by eliminating the dateStart / dateEnd parameters by manually building expression with constant values.
First, a little helper method:
code :
using System;
using System.Linq;
using System.Linq.Expressions;

public static class QueryableUtils
{
    public static IQueryable<T> WhereBetween<T>(this IQueryable<T> source, Expression<Func<T, DateTime>> dateSelector, DateTime? startDate, DateTime? endDate)
    {
        if (startDate == null && endDate == null) return source;
        var startCond = startDate != null ? Expression.GreaterThanOrEqual(dateSelector.Body, Expression.Constant(startDate.Value)) : null;
        var endCond = endDate != null ? Expression.LessThanOrEqual(dateSelector.Body, Expression.Constant(endDate.Value)) : null;
        var predicate = Expression.Lambda<Func<T, bool>>(
            startCond == null ? endCond : endCond == null ? startCond : Expression.AndAlso(startCond, endCond),
            dateSelector.Parameters[0]);
        return source.Where(predicate);
    }
}
//if (dateStart.HasValue)
//    query = query.Where(e => e.outer.ValueDate >= dateStart.Value);
//if (dateEnd.HasValue)
//    query = query.Where(e => e.outer.ValueDate <= dateEnd.Value);
query = query.WhereBetween(e => e.outer.ValueDate, dateStart, dateEnd);
To optimize my linq query which listed as top consuming query in azure query performance insight tool

To optimize my linq query which listed as top consuming query in azure query performance insight tool


By : Jamie
Date : March 29 2020, 07:55 AM
To fix the issue you can do Finally i have reduced my query execution time from 55 seconds to on an average 4.5 seconds by removing AsNoTracking().ToList().
Old query which was taken too much time to execute.
code :
  var onlineData = from od in peopleStatuc.AsNoTracking().ToList()
  var onlineData = from od in peopleStats
Sql Query converting to Linq Query By using Wcf Service Platefrom

Sql Query converting to Linq Query By using Wcf Service Platefrom


By : Per-Ove Andersson
Date : March 29 2020, 07:55 AM
This might help you You may want to take out the password from filter to calculate total number of retries. but use it while actually authenticating the user.
Also once it is successfully authenticated reset the counter to zero.
code :
bool LimitExceeded()
{
var exceeded=false;
var totalRetries =-1;
var attamp = from X in db.tblUsers
                where X.Username == userLogin.Username 
                select X

 if( attamp.Any())
 {
        if(attamp.firstOrDefault().RetryAttempts.HasValue)      totalRetries =attamp.firstOrDefault().RetryAttempts;
        exceeded=  totalRetries>4;
 }
 return exceeded
}
linq query insert exist query string into linq query

linq query insert exist query string into linq query


By : user2288217
Date : March 29 2020, 07:55 AM
Does that help I want to make the query follow the query string of the website but it cant be done in this way, is there any other option to do something like this? For example i can insert name,type,class in the query string but not every variable is need to search for the student , try this:
code :
        var query = from c in db.Students select c;
        if (Request.QueryString["Name"] != null)
        {
            name = Request.QueryString["Name"];
            query = query.Where(c => c.name == name);
        }

        if (Request.QueryString["Type"] != null)
        {
            type += Request.QueryString["Type"];
            query = query.Where(c => c.type == type);
        }

        GridView1.DataSource = query.ToList()
Related Posts Related Posts :
  • How do request a correct access token in ASP.NET Core for Azure AD to access Microsoft Graph
  • How to run a .NET Core console application on Linux
  • UI not updating for bound element
  • C# Odata v4 open type raw values
  • DocumentFormat.OpenXml Modify Creator Propery of Document
  • How to SetBasePath in ConfigurationBuilder in Core 2.0
  • ASP MVC5 public readonly variable changes value when it should not
  • How to conditionally select item from hashset with queryable linq?
  • Progress Bar C# not showing the real progress
  • Correct logic to reconnect in SignalR with HubConnection
  • ComboBox with two or more sections
  • .NET listbox to SQLite DB
  • C# Ninject binding from Dictionary<Type, Type>
  • asp.net mvc -view displaying real-time progress status
  • Getting reference to dependent in service with generic type
  • Implementing EqualityCompare vs overriding GetHashCode and Equals
  • C# Linq Find all indexes of item in List<int> within another List<int>
  • XML image how to display at data grid columns in c#.net
  • How to override Equals and GetHash of HashSet
  • Creating Windows authentication and SQL Server authentication in login form
  • How to interop with Azure Service Bus topics created by MassTransit using Rebus?
  • MVC 5 Google Calendar Integration
  • C# - Use parallel arrays to calculate cost of a phone call in GUI
  • Use a int in entire code
  • How to display newly added element at the top of StackPanel in WPF?
  • T4MVC is generating T4MVC.cs and T4MVC1.cs
  • Remove blur effect on certain controls inside UserControl
  • Setting AWS S3 credentials in C# app
  • does not contain in an ObservableCollection
  • App doesn't run it crashed directly after I started it
  • Is it possible in Entity Framework MVC application to run .sql scripts on a different database
  • Type Inference with Deconstruct tuple assignment extension methods
  • Setting up mock objects for EF dbcontext to test repository methods
  • Using C# in XSLT with MSXSL 6.0
  • Absolute positioning of UIElement in FlowDocument in WPF
  • Display debuggers not showing up in Visual Studio 2017
  • Discord.NET Users playing the same game
  • Azure function output API call to 3rd party service
  • Unable to determine the relationship represented by navigation property ASP.NET core 2.0 Entity Framework
  • Regex to find group of Regex inside a word
  • When calling a method, when to reference the class, and when to reference the object?
  • AmazonCloudWatchLogsClient async methods failing with no error
  • Create FileStream in memory instead of saving a physical file on disk
  • ViewBag data coming from ActionFilter is persisting in session even after database
  • ERROR: the name 'lvSubCategories' does not exist in the current context
  • Why datetime can't recognise the string?
  • Getting 500 error while requesting to webservice using Ajax AutoCompleteExtender
  • The property 'x' is not a navigation property of entity type 'y'
  • ASP.NET MVC - How to generate empty input boxes in loop when model is empty?
  • Need help writing regular expression
  • Add/remove buttons to a panel with an arraylist c#
  • Linq .Where(type = typeof(xxx)) comparison is always false
  • Using EF6 Code First without migrations to an existing db how do I specify column names of the many to many join table?
  • C# - Using Thread.Sleep precisely in a console application
  • Add item to a List<Tuple> inside another list
  • Double[,], inversion C#
  • Counting a string to ensure the input is within a min/max boundary
  • Assign invalidValue to Enum variable (why is this not throwing an Exception?)
  • Namespace or type specified in the project-level Imports 'System.Threading.Tasks' doesn't contain any public member or c
  • Selenium with .net core: performance impact, multiple threads in IWebElement?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org