ADO.NET :: Dynamically Adding MyColumn LIKE '%@MyParameter%' To The Linq IQueryable Object
Jan 11, 2011
My situation is as follows:
I do some filtering on the IQueryable<MyType> object using the Contains() function in Linq, which in effect adds: MyColumn LIKE '%@MyParameter%' to the linq requestI want to make the function more generic, which could operate on a IQueryable object of an unknown type. In such case I do not know the type yet, therefore I can not add a standard .Contains() function. All I have present are the IQueryable object, the MyColumn and MyParameter as a string text. I need to be able to add "MyColumn LIKE '%@MyParameter%'" to the Linq object, dynamically ...
How can I write a piece of code that would run the Contains() on the IQueryable, knowing the Column name (as string) and the parameter value (as a string too) - I basically want to add this: MyColumn LIKE '%@MyParameter%' to the Linq where clause.
I have found something doing the .Where() function dynamically, but I do not entirely understand what is happening in there, so I struggle to convert it to Contains():
[Code]....
adding dynamic .Contains() to the IQueryable object only using the string column name and the string value
View 3 Replies
Similar Messages:
Aug 23, 2010
Is there option to convert from Linq.IQueryable to DataTable with some sort of CopyToDataTable() function. I am trying this.
View 2 Replies
Jul 4, 2010
I'm creating a repository and service layer in my app, and my repo has a very simple function
Public Function GetRegions() As IQueryable(Of Region) Implements IRegionRepository.GetRegions
Dim region = (From r In dc.Regions
Select r)
Return region.AsQueryable
End Function
Now in my Service layer I've got a function like this
Public Function GetRegionById(ByVal id As Integer) As Region Implements IRegionService.GetRegionById
Return _RegionRepository.GetRegions().Where(Function(r) r.ID = id).FirstOrDefault
End Function
But i can't figure out how to add And r.isActive = True
how to have multiple operators in this query?
View 3 Replies
Jan 11, 2010
Is it possible to add attributes in a linq query along with the other object data?
Here's what I have
[Code]....
But I'd like to add a custom attribute to each RadComboBoxItemData object in the query instead of having to do a foreach loop after the linq query to add the attributes on..
View 1 Replies
May 26, 2010
I am using System.Linq.Dynamic to create the following query at runtime:
[Code]....
I can then successfully display vMediaQ in a GridView.But I need to be able to access the individual fields (column headers and data) in vMediaQ, which is of type System.Linq.IQueryable.
View 11 Replies
Jul 26, 2010
I added dynamicly infragistics webpanel in my codebehind using :placeHolder.Controls.Add(ctlWebpanel); but i got this javascript error in my ASP.net page in runtime :'currentStyle' is null or not an object
How to set the style to remove that error ?
View 2 Replies
Aug 25, 2010
If I have below code, how to make it work as it has below compile error:
Error: cannot implicitly convert type 'System.Linq.Iqueryable<system.data.DataSet> to 'System.Data.Dateset'. An explicit conversion exists.
public DataSet GetProductList()
{
using (var sdatabase = new DatabaseDataContext())
{
IQueryable<DataSet> result = wmsdatabase.ExecuteQuery<DataSet>(@"SELECT productid, productname from product group by productid, productname").AsQueryable();
return result; // Compile error here
}
}
View 1 Replies
Mar 11, 2011
I am using LINQ and sending a linq object to the view and trying to show it in a textbox like this
<%=Html.TextBox("petname",Model.PetName) %>
But I am getting error, how can I show (PetRecord.PetName) which is my linq entity
View 1 Replies
Feb 19, 2010
I have just recently converted my VB code to C# and now having this error when I try to add an item to my listbox, and the value is coming from the item page. I get the error at this segement:
lstboxCart.Items.Add(cartItem.Display());
My listbox is supposed to add the product's name, quantity, and price onto one row.
Here's what I have so far:
[code]...
[Code]....
[Code]....
My guess is that the source of the problem could be in the foreach loop from my cart class, shouldn't I be using that for arrays only? If I need to post any markup code or any other class, let me know.
View 7 Replies
Mar 12, 2010
I am writing a plugin to help with a current ERP system we have that I am not allowed to modify the data structure at all. The table I am dealing with has over 100 columns and I am wanting to set my linq object propertychanged event and submitchanges or do I really have list out each property and set it equal to the new one?Below is an example of what I am trying to do:
[Code]....
View 4 Replies
Mar 9, 2010
txtLastName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Last_Name.ToString();
Like that I have large number of controls on my form. I have dought, if I assigned like this, db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Last_Name.ToString(); to every control, then I have set of controls like,
ddlSalutation.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Salutation.ToString();
txtLastName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Last_Name.ToString();
txtFirstName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).First_Name.ToString();
txtMI.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Middle_Initial.ToString();
txtAddress.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Home_Address.ToString();
txtCity.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).City.ToString();
ddlState.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).State.ToString();
txtZip.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Zip_Code.ToString();
txtSSNo.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ssn.ToString();
txtMRNo.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Mr_No.ToString();
txtDOB.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Birth_Date.ToString();
RBGender.SelectedItem.Value = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Gender.ToString();
RBMaritalStatus.SelectedItem.Value = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Marital_Status.ToString();
txtHomePhone.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Home_Phone.ToString();
txtWorkPhone.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).WorkPhone.ToString();
txtCellPhone.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).CellPhone.ToString();
ddlSuffix.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Suffix.ToString();
txtReligion.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Religion.ToString();
txtEmail.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Email.ToString();
txtSSOName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ssn.ToString();
txtPatientKin.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Patient_Kin.ToString();
txtRelationWithPatient.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Kin_Relation.ToString();
txtPhoneNo.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Kin_Phone.ToString();
ddlPreferredPharmacy.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Id_Pharmacy.ToString();
txtEmergencyContactName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Emergency_Contact_Name.ToString();
txtEmergencyContactNumber.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Emergency_Contact_Phone.ToString();
txtRelation.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Kin_Relation.ToString();
txtRace.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Race.ToString();
ddlHowDidPatientFindUs.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).How_Found.ToString();
txtEmployerName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Employer_Name.ToString();
txtEmployerOccupation.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Employer_Occupation.ToString();
txtEmployerPhone.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Employer_Cell_Phone.ToString();
txtEmployerAddress.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Employer_Address.ToString();
txtEmployerCity.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Employer_City.ToString();
ddlEmployerState.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Employer_State.ToString();
txtEmployerZip.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Employer_Zip.ToString();
txtRecordsReleasedTo.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Records_Released_To.ToString();
txtOtherInfo.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Other_Info.ToString();
txtPopupNote.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Popup_e.ToString();
ddlPPlanName.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Insurance_Name.ToString();
txtPGroupNo.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Group_No.ToString();
txtPIDNo.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Id_No.ToString();
txtPPhone.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Plan_Phone.ToString();
txtPVerifiedWith.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Verified_With.ToString();
txtPVerifiedPhone.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Verified_Phone.ToString();
txtPEffectiveDate.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Effective_Date.ToString();
txtPExtDate.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Ext_Date.ToString();
if (db.usp_ATI_FetchPatientDetails(iPatientID).Count() > 0)
{
txtPGLastName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Grn_Name.ToString();
txtPGFirstName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Grn_Name.ToString();
txtPGMI.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Grn_MI.ToString();
txtPGBirthGDate.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Grn_Dob.ToString();
txtPGAddress.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Grn_Address.ToString();
txtPGCity.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Grn_City.ToString();
ddlPGState.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Grn_State.ToString();
txtPGZip.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Grn_Zip.ToString();
txtPGEmployerFirstName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Grn_Emp_Fname.ToString();
txtPGEmployerLastName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Grn_Emp_Lname.ToString();
txtPGEmployerPhone.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Grn_Emp_Phone.ToString();
txtPGEmployerOccupation.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Grn_Emp_Occupation.ToString();
txtPGEmployerAddress.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Grn_Emp_Address.ToString();
txtPGEmployerCity.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Grn_Emp_City.ToString();
ddlPGState.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Grn_Emp_State.ToString();
txtPGEmployerZip.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Grn_Emp_Zip.ToString();
ddlPGPatientRelationshipToGuarantor.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Grn_Rel_With_Pat.ToString();
txtPGOtherInsuranceNotes.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Other_Notes.ToString();
txtPGAuthorization.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Authorization.ToString();
txtPGAob.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_AOB.ToString();
}
if (db.usp_ATI_FetchPatientDetails(iPatientID).Count() > 1)
{
txtSGLastName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_Grn_Name.ToString();
txtSGFirstName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_Grn_Name.ToString();
txtSGMI.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_Grn_MI.ToString();
txtSGBirthGDate.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_Grn_Dob.ToString();
txtSGAddress.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_Grn_Address.ToString();
txtSGCity.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_Grn_City.ToString();
ddlSGState.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_Grn_State.ToString();
txtSGZip.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_Grn_Zip.ToString();
txtSGEmployerFirstName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Grn_Emp_Fname.ToString();
txtSGEmployerLastName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Grn_Emp_Lname.ToString();
txtSGEmployerPhone.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Grn_Emp_Phone.ToString();
txtSGEmployerOccupation.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Grn_Emp_Occupation.ToString();
txtSGEmployerAddress.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Grn_Emp_Address.ToString();
txtSGEmployerCity.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Grn_Emp_City.ToString();
ddlSGState.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Grn_Emp_State.ToString();
txtSGEmployerZip.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Grn_Emp_Zip.ToString();
ddlSGPatientRelationshipToGuarantor.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_Grn_Rel_With_Pat.ToString();
txtSGOtherInsuranceNotes.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_Other_Notes.ToString();
txtSGAuthorization.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_Authorization.ToString();
txtSGAob.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_AOB.ToString();
}
My question is that, for each control the Stored Procedure called or not? If it is yes then it is time consuming and I need to use LINQ to DataSet or LINQ to Object rather than to call SP for each control. What is difference between LINQ to DataSet and LINQ to Object?
View 5 Replies
May 10, 2010
[code]....
this code give that solution.but if any one of the field have null(example:r.urrQuickLinkRights contain the NULL) then only it will throw error like Object reference not set to an instance of an object.
View 2 Replies
Jul 1, 2010
I have two tables, subscriptions and topics. Each subscription is related to a specific TopicID (PK for topics table). The first query works fine and retrieves the topicID's of all videos that were uploaded today. The problem occurs when I try and then use the results of query1 as a where-in clause for query 2. I keep receiving object reference not set to instance of an object.
Query 1 IQueryable<int> topics = (from t in dataLayer.Videos
where SqlMethods.DateDiffDay(t.DateCreated, DateTime.Today) == 0
select t.TopicID).Distinct(); [code]....
I have looked at some samples around the net and they all seem to be identical to mine.
View 1 Replies
Oct 31, 2010
i am choosing a category from a DropDownList controll, and if want to add a new category at the same time i have a TextBoks for it, i have create a Model, BLL and DAL classes, my problem is:
in the DAL class i want to add a new row to Question, but i need to check first if the object.category exsist in the table Category, if it does i want to get the Cid for it if it dosen't exist i want to create a new raw then get the Cid, this is my code:
public string add(Faq inFaq)
{
using (var db = new DBClassDataContext())
{
try
{
var se = from Category in db.Categorys
where Category.category == inFaq.category
select Category.Cid;
if (se.Count() == 0 ).........
View 4 Replies
Dec 25, 2010
i want add a record to my table(News) in the database School.
so i create a class for news table look like this:
public class News
{
private int _newsid;
private string _datetoshow;
private string _title;
private string _description;
private string _writtenby;
public int NewsID
{
get { return this._newsid; }
set { this._newsid = value; }
}
public string DateToShow.......
pop up is:
'system.Data.Linq.Table <New>' does not contain a definition for add and no extension method 'Add' accepting a first argument of type 'System.Data.linq.Table<New>' could be found (are you missing directive or an assembly reference?)
View 3 Replies
Feb 16, 2010
I have a simple query i.e.
var trips = from t in ctx.Trips
select t;
The problem is that I have an extra property on the Trip object that needs to be assigned, preferably without iterating through the returned IQueryable.
Does anyone know how to set the value during the query? (i.e. select t, t.property = "value")
View 3 Replies
Oct 21, 2010
I have two tables in the dbml, Table1 and Table2. Table1 has a Table1ID as primary key and Table2 has Table1ID as foreign key.I have an instance of Table1 called table1,
[Code]....
then I create another instance of Table1 called anotherTable1,
[Code]....
At this point, my intention is to have table1 containing a list of Table2 and anotherTable1 containing 0 Table2. However, both table1.Table2 and anotherTable1.Table2 become 0 count.
View 1 Replies
Oct 9, 2010
I tried to add a custom property to the data model:
public partial class Department
{
public string ExtensionIdName
{
get
{
return Extension.ExtensionName;
}
set
{
}
}
}
It seems that it works, but when I bind the data to a ListView it shows all the properties except the property I added manualy (ExtensionIdName).
View 2 Replies
Feb 10, 2011
how can i add li to ui in code behind side dynamically .
View 10 Replies
Feb 16, 2011
Just wondeing is there a way to add a group of single objects to a row in a db. For example
i have a Class table and i want to have a student column in the stable that can hold all the students i add to that specific class. Ie all the students in mathematics.
Is there a way to do this in sql server and then implemenmt it in vs?
View 3 Replies
Jan 7, 2010
I have a pretty complex Linq statement with multiple joins, but am having a problem with an orderby statement.
I think I can reduce the question down a bit, but will expand if needed.
First my object has the following properties:
myObject.ID This is a basic Int
myObject.BrandName This is my HashSet<string>.
I need to sort my Object by the BrandName using the lowest or highest value depending on if I am sorting ascending or descending.
View 2 Replies
Apr 19, 2010
I have just started using LINQ with VS2008. I have added extra columns to my table, saved the changes, but class ClassName.Designer.CS didn't get updated. What do I have to do to updated the class? Do I have to do it manually, or is there a way to automatically synchronize tables and ClassName.Designer.CS?
View 2 Replies
May 25, 2010
I have a table added to a dbml file in my website. The website is already deployed to Live server. Now I have been instructed to a add a new field to the table. The field will be defaulted as getdate().
I don't plan to modify my dbml file for this change since the filed holds a default value. Will it cause any issue(performance related or any other). I am sure that I will not have to use the newly added field in the website. I am new to LINQ.
View 3 Replies
Feb 4, 2010
I am new to LINQ but not >net. I do understand SQLDataSource, etc. I was just told by a coworker not to use a LINQ to SQL Class for my new project (Bank.dbml). I was told to use instead the ADO.Net Entity Data Model (bank.edmx).
BankModel.edmxBank.dbml
When only using ADO.Net Entity Data Model I try to associate a GridView with a new LinqDataSource I get no options. When I add a LINQ to SQL Class I get the option to use it but it is empty. Is this because all my LINQ classes are mapped in the ADO.Net Entity Data Model (bank.edmx)? Can someone tell me (or point me to) what the differences are in these two?
View 4 Replies
Jun 21, 2010
I have a table with 4 cells and three rows. All rows have a textbox in it. I have a button at the top. I want to add a new row in that table when that button ic clcikded with same formatting as above row. Above row format is like this.
<tr valign="top">
<td>1.
</td>
<td align="left">
<asp:TextBox ID="txtC1Fname" runat="server" Width="150px"></asp:TextBox>
</td>
<td align="left">
<asp:TextBox ID="txtC1LName" runat="server" Width="150px"></asp:TextBox>
</td>
<td align="left">
<asp:TextBox ID="txtC1DOB" runat="server" Width="150px"></asp:TextBox>
</td>
</tr>
How Can I do this ?
View 4 Replies