Go Premium for a chance to win a PS4. Enter to Win

x

LINQ Query

535

Solutions

393

Contributors

Language Integrated Query (LINQ) is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages, although ports exist for Java, PHP, JavaScript and ActionScript. LINQ extends the language by the addition of query expressions, which are akin to SQL statements, and can be used to conveniently extract and process data from arrays, enumerable classes, XML documents, relational databases, and third-party data sources.

Share tech news, updates, or what's on your mind.

Sign up to Post

The codes below is working ok. I just need to make VAR response to be sorted.
How can I do that?

   public static List<Make> GetVehicleMakeList()
        {
            List<Make> lstMake = new List<Make>();
            HttpClient objClient = new HttpClient();
            try
            {
                var response = objClient.GetStringAsync(Utility.Enumeration.vehicleMakeAPICall).Result;
                if (!string.IsNullOrEmpty(response))
                {
                    VehicleMakeAPIResponse objMakeResponse = Newtonsoft.Json.JsonConvert.DeserializeObject<VehicleMakeAPIResponse>(response);
                    return objMakeResponse.Results;
                }

            }
            catch (Exception ex)
            {

                //log error message here
            }
            return lstMake;
        }

Open in new window

0
Free Tool: ZipGrep
LVL 11
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

This is fragment of my .cs code

        public arAbonamenty_page()
        {
            InitializeComponent();
 

            Nexo_ARWALEntities myNexo_ARWALEntities = new Nexo_ARWALEntities();

            Nullable<Int32> grupa_tw = new Nullable<Int32>();
            grupa_tw = null;
            short? kiedy_fakturować_combo = new Nullable<Int16>();
            bool? bool_okres_płatności = new Nullable<bool>();
            if (okres_płatności.SelectedIndex == 2)
            {
                bool_okres_płatności = null;
            }
            else
                bool_okres_płatności = Convert.ToBoolean(okres_płatności.SelectedIndex);

            Nullable<bool> kiedy_fakturować = new Nullable<bool>();
            kiedy_fakturować = Convert.ToBoolean(kiedy_fakturować_combo);

            var query = (from myabonamenty in myNexo_ARWALEntities.ArAbonamenty
                         join nexotowary in myNexo_ARWALEntities.Asortymenty
                         on myabonamenty.nexo_towar equals nexotowary.Id
                         join myklienci in myNexo_ARWALEntities.ArKlienci
                         on myabonamenty.id_klient equals myklienci.id_klient
                         where (grupa_tw == null || (grupa_tw != null && nexotowary.Grupa_Id == grupa_tw))
                         where (myabonamenty.czy_fa_auto_na_początku_okresu == null || (kiedy_fakturować != null && myabonamenty.czy_fa_auto_na_początku_okresu == kiedy_fakturować))

                         

Open in new window

0
How to find adjust and round value from given range in another table.

I have below values.

[0] SUB A=140
[1] SUB C=60

The above values needs to be check in the below TABLE B.

Dept      SUB A      SUB B      SUB C
A1                     
A2                     
A3      100              
A4                    25
A5                     
A6      50              
A7                     
A8                     
A9      25              
A10                     
A11                     
A12      10              
For example,

let us consider SUB A=140

First we need to find the columns in TABLE A along with Dept=A3 rows (A3 is parameter which we need to pass finding column along with this)

My objective is find the range in table and adjust the value near to this based on my range.

For example,

My SUB A=140

my selected range is "100"


So the Final result is nearest value of SUB A=200 (it means it will consider the range is 100 200,300,etc)

If SUB B=220 then final value is SUB A=300

For Second one,

SUB C=60 ==> Final value is SUB C=75 (the range statrts from 25,50,75,etc)

Final Output

[0]SUB A=200

[1]SUB C=75


How to write a code in C# or LINQ in C#..?
0
1. How can get the list (element (State)))  filter by state if parameter is given e.g. (CA) order by State asc?
2. How can get the list (element (Name)) filter by Status = Online and state = "CA" order by Name asc?

3. How can get total count of Bond filer by state?
4. How can get total count of Bond filter by Status (e.g. Online)?

I would like to see in c#.

Thanks,


<Surety>
<SuretyLine>
<Commercial>
<Bond>
        <GeneralInformation UI="BondInfo">
          <Name ID="bondName" PrefillValue="Yes">C</Name>
          <State ID="bondState" PrefillValue="Yes">CA</State>         
        </GeneralInformation>              
        <Status>Online</Status>
</Bond>
<Bond>
        <GeneralInformation UI="BondInfo">
          <Name ID="bondName" PrefillValue="Yes">Z</Name>
          <State ID="bondState" PrefillValue="Yes">CA</State>         
        </GeneralInformation>              
        <Status>Online</Status>
</Bond>
<Bond>
        <GeneralInformation UI="BondInfo">
          <Name ID="bondName" PrefillValue="Yes">B</Name>
          <State ID="bondState" PrefillValue="Yes">FL</State>         
        </GeneralInformation>              
        <Status>Online</Status>
</Bond>
</Commercial>
</SuretyLine>
</Surety>

Open in new window

0
I need help to create the LINQ query for EF. it is easy in T-sql, not that easy in LINQ.
Here is the data structure:
Group contains multiple tags. (Tag: tagId, groupId, tagName)
Group contains memberships. (Membership: membershipId, groupId, userPin)
Memberships need to link Person to get the DisplayName.  (person: PersonId, userPin, DisplayName)
So getAll():
return _db.Groups
.include(x => x.Tags)
.include(x => x.Memberships)
.include(x => x.memberships.Select(y => y.Person));

Now I want it returns only those groups whose memberships contains userPin=1234. In other words, given user pin=1234, find all the groups that user joins.

In T-sql:
select g.*, t.*, m.*, p.*
from Group g
inner join Tags t on g.groupId = t.groupId
inner join membership m on g.groupId = m.groupId
inner join person p on m.userPin= p.userPin
where m.userPin= 1234

How do I accomplish that in LINQ (method syntax)? Your help will be greatly appreciated. Thanks
0
Hi,
I need to create a report in SharePoint 2013 , on premises , There is a custom SharePoint list which has username, Manager and Status. say it SPLIst
I have created another SharePoint list as external content type using SQL procedure which returns all all active users. In this second list say DBList I have username and their department.
My requirement is , I need to compare the two lists and whoever is not found in SPList, should be marked as "Not Started".

Could you please help me to achieve this?

Thanks in advance.
Azra
0
I have been tasked with adding some very specific searching behaviour to a MVC application using Entity Framework.  

The searching should be able to get:

Entries with two or more words that are not just exactly next to each other. If they type in "The Revenge":
  • The Revenge
  • The Horrible Revenge
  • Revenge of the Machines

Parts of words. If they type in "Smith":
  • Mr and Mrs Smith
  • Meet the Smithsons
  • The Incredible Blacksmith

I have written the following method in my controller class:

public ActionResult Index(string searchString)
        {

            var films = from s in db.films
                        select s;

            if (!string.IsNullOrEmpty(searchString) && !searchString.Any(x => Char.IsWhiteSpace(x)))
            {
                searchString.Trim();
                films = films.Where(s => s.title.Contains(searchString)
                    || s.title.StartsWith(searchString)
                    || s.title.EndsWith(searchString)
                    || s.genre.Contains(searchString)
                    || s.genre.StartsWith(searchString)
                    || s.genre.EndsWith(searchString)
                    || s.synopsis.Contains(searchString)
                    || s.synopsis.StartsWith(searchString)
                    || s.synopsis.EndsWith(searchString)
            }
      

Open in new window

0
Hi Experts,
I need help setting a default value to 0, when the returned value is null, or 0.
I have tried the code below but I get a blank\empty field in my table.  See code below, and let me what I am doing wrong.

CODE
var paper = (db.Manifests.Where(m => m.ID == ID && m.ProcessedDate.Value.Month == DateTime.Today.Month).Sum(m => m.Claims != null  ? m.Claims : 0)).Value;
vals.Add((paper.ToString().Length > 0) ? string.Format("{0:###,###}", paper) : "0");

Open in new window



Thank you,
mrotor
0
how to get coming expires before 7 month  in linq
0
I have BPM (Method Directive) in Epicor 10.1.600.

BO:  JobEntry

Method:  ChangeJobHeadProdTeamID

The user trigger its from the Job Entry screen by changing the "Prod Team" field.  The BPM has a Post-Processing directive, which looks like this:
foreach (var ttJobHead_Row in ttJobHead)  //ttJobHead
{
  using (var txScope = IceContext.CreateDefaultTransactionScope())
  {
    //get the header row and update it
    var jobheadrow = (from JobHead_Row in Db.JobHead.With(LockHint.UpdLock)
                      where JobHead_Row.Company == ttJobHead_Row.Company
                      && string.Compare(JobHead_Row.JobNum, ttJobHead_Row.JobNum, true) == 0
                      select JobHead_Row).FirstOrDefault();
               
               if (jobheadrow != null)
               {
                 jobheadrow.Serial_c = callContextBpmData.Character01;
                 jobheadrow.Height_c = Convert.ToInt32(callContextBpmData.Number01);
                 jobheadrow.Width_c = Convert.ToInt32(callContextBpmData.Number02);
                 jobheadrow.PaintColor_c = callContextBpmData.Character02;
                 
               } 
      
    }
    
    Db.Validate();
    txScope.Complete();    

  }
   
}

Open in new window


It executes successfully, and brings me back to the Job Entry screen.  When I select "Save" on the Job Entry screen, I get the error:
error
I have tried putting in:
var jobEntryBO = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.JobEntrySvcContract>();
var currentJob = jobEntryBO.GetByID(ttJobHead_Row.JobNum);
this.dsHolder.Attach(currentJob);

Open in new window


before the line:
txScope.Complete();

But still receive the error.  Would you know what is wrong here?
0
Ask an Anonymous Question!
LVL 11
Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Below codes is to call Twilio API and get the sms historical conversation for one phone no. However, it takes over 15 seconds and the total records is actually just 5 conversation.

Have any experts worked with Twilio in the past and know another way to get SMS conversation in a faster mode?
Thanks,



TwilioClient.Init(accountSid, authToken);
            var messages2 = MessageResource.Read().Where(x => x.From.ToString() == fromPhoneNo);
            var messages3 = MessageResource.Read().Where(y => y.To == fromPhoneNo);
            var all = messages2.Concat(messages3).OrderByDescending(z => z.DateCreated);

Open in new window

0
Hi Experts,
I need help with a 'System.ObjectDisposedException' error I am getting in my C#.net Mvc.Net application.
I have posted my code below.

Code where I retrieve data from the database
private static List<InboundReject> getRejects()
{
    using (Utilities.RejectLetter db = new Utilities.RejectLetter())
    {

        var _rejectLetter = from m in db.InboundRejects
                            join c in db.InboundManifests on m.InboundManifestID equals c.InboundManifestID
                            where m.LetterPrintDate == null
                            select m;

        return _rejectLetter.ToList();
    }
}

Open in new window


Code where I attempt to use the data retrieved from the database
NOTE: the last statement reject.InboundManifest.Market.ToString() is what is throwing the error.
List<InboundReject> Rejects = getRejects();
foreach (InboundReject reject in Rejects)
{
    generateLetters(
        reject.DCN.ToString(), 
        reject.Description.ToString(),
        reject.BillingProviderName.ToString(),
        reject.BillingProviderAddress.ToString(),
        reject.BillingProviderCity.ToString(),
        reject.BillingProviderState.ToString(),
        reject.BillingProviderZip.ToString(),
        reject.EDOS.ToString(),
        reject.TotalCharge.ToString(),
        reject.PatientLName.ToString(),
        reject.PatientFName.ToString(),
        reject.InsuredID.ToString(),
        reject.PatientAccountNumber.ToString(),
        reject.InboundManifest.Market.ToString());
}

Open in new window


Thank you in advance for your help,
mrotor
0
I need to get a random record from  sql database with Linq query in entity.
0
I trying to create a query similar to below.    

I want a list of opportunities by FKVCCenterID.  But I have to go right back to the organisation and then to the VCCentres get this.

VCCentres have Organisations
Organisations have Opportunities


This query works except it returns an aynonmous type instead of the type i want which is tblOpportunities

  var opportunities = (from org in _ctx.tblVCCenterOrganisations
                join vc in _ctx.tblOrganisations on org.FKOrganisationID equals vc.OrganisationID
                join ops in _ctx.tblOpportunities on org.FKOrganisationID equals ops.FKOrganisationID
                select new
                {
                    FKVCCenterID = org.FKVCCenterID,
                    OpportunityID = ops.OpportunityID,
                    Title = ops.Title,

                }
            ).Where(x => x.FKVCCenterID == 999).Take(take).Skip(skip);


If i specify the type "select new tblOpportunity()" the where clause breaks because the tblOpportunity does not contain the FKVCCenterID
  var opportunities = (from org in _ctx.tblVCCenterOrganisations
                join vc in _ctx.tblOrganisations on org.FKOrganisationID equals vc.OrganisationID
                join ops in _ctx.tblOpportunities on org.FKOrganisationID equals ops.FKOrganisationID
                select new tblOpportunity()
                {
                    OpportunityID = ops.OpportunityID,
                    Title = ops.Title,

    …
0

LINQ Query

535

Solutions

393

Contributors

Language Integrated Query (LINQ) is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages, although ports exist for Java, PHP, JavaScript and ActionScript. LINQ extends the language by the addition of query expressions, which are akin to SQL statements, and can be used to conveniently extract and process data from arrays, enumerable classes, XML documents, relational databases, and third-party data sources.

Top Experts In
LINQ Query
<
Monthly
>