ADO.NET :: Linq To SQL - Crippled For Complex String Comparisons?

Nov 15, 2010

The problem which I present involves needing a more complex string comparison mechanism with Linq to handle user driven queries of irregularly formatted data. The one instance I will use to explain this problem is phone numbers. To search a phone number you want to compare just the numbers (This system has to be able to handle internation as well as US domestic numbers). So users have been able (through many years) to enter phone numbers in any format they desire, ex:

555.555.5555
or
+1 555 555 5555
or
(555) 555-5555
etc

So I have a query I would LOVE to use, but because SQL cannot translate regx objects I have very few options that I am aware of. The query I want to use is as follows:...............

View 3 Replies


Similar Messages:

DataSource Controls :: LINQ Mapping To Complex Business Objects?

Feb 5, 2010

I have two business objects mapped via LINQ to tables. One of the objects contains an instance of the other object and share a key as an identifier.I want to retrieve Class A and within class A all of Class B's values as well. What I am doing is this:

[Code]....

[Code]....

This seems a little clunky, as in slow. Is there a better way to get the Class B (User) information without making a query every time?

View 4 Replies

MVC :: Saving A Complex Child Object After Post (LINQ To SQL Model Binding With MVC)

Jan 6, 2011

I am using ASP.Net MVC2 and LINQ to SQL. I am using DataAnnotations and model binding in conjunction with a Form/View and its working beautifully well. Loving that.. My view is an "Add new Employee" form that's adding a new "Employee" complex object. Every Employee also has a child complex object called an "Address".
I am using the bound Html helpers in the view, such as Html.TextBoxFor(model => model.NewEmployee.FirstName) for example. Working beautifully well, validating beautifully well both client and server and coming into the controller fully populated and ready to be saved! Exciting.. ModelState.IsValid returns true and I go to save the new Employee.

The Employee is created fine but the system also creates a blank/new Address record in my Addresses table even when the Address fields are blank! How can I prevent any Address from being created, in situations where I ONLY want to create a new Employee with no Address. An example is when the user supplies an existing Address, then I wish to simply set the new Employee's AddressID to that of an existing physical address (I hope that makes sense). But it could apply to any situation where you need to create a new complex object, but you don't wish for LINQ to create any of its child complex objects. I have tried setting NewEmployee.Address = null after it is received in the controller, but even after that, a blank/new Address is still created. Even if I try NewEmployee.Address = SomeExistingAddress, it does correctly link the Employee to the existing Address, but it STILL goes off and creates another redundant new/blank address record! Which is really weird..

View 10 Replies

MVC + LINQ To SQL Model Binding - Saving A Complex Child Object After Post

Jan 5, 2011

I have a "Create New Employee" ASP.Net MVC form. My complex object is an Employee and an Employee has an Address, which is another Complex object. On my View/Form I collect all required values for both the Employee and the Address. I'm using the bound HTML helpers such as: Html.TextBoxFor(model => model.EmployeeAddress.StreetName)

AND

Html.TextBoxFor(model => model.NewEmployee.FirstName)

This is all working beautifully well. Model binding is working like a dream, both server side and client side validation using DataAnnotations is working beautifully well and I am nicely receiving my populated complex objects as expected in the Controller.. Now I'm trying to save.. The Employee should always be newly created, because its an "Add New Employee" form. But sometimes the Address is an existing Address and I don't want to insert another one. Rather, I just want to link the Employee to the existing AddressID of the one that already exists in the database.

So I wrote a nifty GetExistingOrCreateNewAddress(Address PostedAddress) method which works great so I end up with the correct Address to use and link to the about to be saved Employee object. This is all happening in the same DataContext, so no problems there..

BUT even when I link the about to be saved Employee object to an existing Address, on save a new/empty Address row is created in my Addresses table. Even though the newly created Employee does link correctly to the existing Address I told it to! Why is it so??? And how can I save the new Employee without LINQ automatically creating a blank Address for me. Because I'm explicitly specifying an existing Address it should be linked to instead!

[HttpPost]
public ActionResult CreateEmployee(EmployeeDetailsViewModel NewEmployeeDetails)
{
if (ModelState.IsValid)
{
EmployeeRepository ER = new EmployeeeRepository();
// Fetch or Create the appropriate Address object for what has been entered
Address ActualAddress = ER.GetExistingOrCreateNewAddress(NewEmployeeDetails.EnteredAddress);
// Link this Address to the "about to be saved" Employee
NewEmployeeDetails.Employee.Address = ActualAddress;
// Lock it in..
ER.SaveNewEmployee(NewEmployeeDetails.Employee);

View 2 Replies

Web Forms :: Complex String Operations?

Feb 17, 2011

Does anyone have a tricky tip to simplify my complex String Operations? I receive a string sequenze from database which i have to manipulate on RowDataBound of an GridView, put the String into several controls. The String looks like this:Here goes a introduction string with easy formating options such as {blue}blue text{/blue}

{CONTROL}{ParamsForControl|ParamsForControl}Text for Control 1{/CONTROL}
{CONTROL}{ParamsForControl|ParamsForControl}Text for Control 2{/CONTROL}
{CONTROL}{ParamsForControl|ParamsForControl}Text for Control 3{/CONTROL}

Some Text at the end.My first try was easy because I haven't had an introducing and a ending text, so I split the String at "{CONTROL}" extract the Parameters and replaced "{/CONTROL}" with nothing, works fine...But if i now split at "{CONTROL}" how to handle the text in front of and behind them... I do a lot of string.IndexOf and String.LastIndexOf operations but I hope there is an easier way...Result should be:

Introduction Text = Label
Control = UserControl
Control = UserControl

View 5 Replies

AJAX :: Can Not Send Complex String To WebMethod?

Mar 7, 2010

Have try to send the complex string that is created(serilize) from data.If I write just a regular string there is no problem but I want to sendover the array data as a string and then deserilize it does not work.What happens is that the webmethod 'save' never start. No error occurs!I suppose it is becouse the string contains a lot of " but I dont know howto change that and then bee able to deserilize it to the object.The string 'strData':

"{'JSONString': '[{"Show":false,"SortOrder":"","QuestionText":"Ingen rapport lämnas till kund då följande muntliga rapport har lämnats:","DefaultValue":"","CSS":"","Note":"","RQID":"Label","FunctionNr":0},{"Show":false,"SortOrder":"","QuestionText":"Lämnar

[code]...

View 2 Replies

ADO.NET :: Concatenate Linq To String?

Sep 24, 2010

Below is sample linqtosql, is there possible to concate linq in select statement.becuz i wan to return vary number of column

[Code]....

[Code]....

View 3 Replies

ADO.NET :: How To Convert Bool Value Into String In LINQ

Dec 29, 2010

I have the following query in which I have to convert the 'bool' valu into 'string' value as "Y" or "N". I have a class defined called ChartDosCodeInfoStruct which definesQAIndicator as String. The value I am feteching from DB is a bool value. I need to take this bool value and accordingly assignQAIndicator= "Y" or "N".

UserManager userManager = (UserManager)BaseEntityManager<DataAccessLayer.User>.GetSingleInstance();
List<User> user = userManager.GetCodersForChart(_currentChart.ChartId);
UIConfigurationObject.CoderForChart.value = user.First().FullName.ToString();
[code]...

View 2 Replies

ADO.NET :: Trim String In LINQ Query?

Mar 17, 2011

I have the following query;

[Code]....

How do I modify to trim all strings?

View 3 Replies

ADO.NET :: Return String In LINQ Method?

Mar 9, 2011

I'm really new to ASP.Net and for a school project we have to create a login form. Now I have managed to create a login with LINQ doing the following:

[Code]....

And in my html page:


protected void Test_Click(object sender, EventArgs e)

{

if (Class1.Controle(Convert.ToInt32(txt1.Text), txt2.Text))

[Code]....

I was thinking something amongst those lines, but I can't call p.GebruikerWachtwoord. So I'm guessing this is completely wrong.I hope somebody can help me figure this out, and I apologise for the poor explanation, English isn't my native language.

View 3 Replies

ADO.NET :: Cannot Convert String To Bool Error In LINQ

Oct 22, 2010

cannot convert string to bool error in LINQthis is my code:

[Code]....

View 4 Replies

ADO.NET :: Converting Date To String And Formatting It Linq To SQL?

Aug 2, 2010

I have problem in converting date to string I am using cstr(p.tripstart) , which is returning Date as 12 Aug 2010 12:AM I need to make formating This is my code :

[Code]....

View 9 Replies

ADO.NET :: Timestamp Wrongly Treated By LINQ / ASP As String

Feb 12, 2011

I was following a MSDN walkthrough [URL] which is a very simple ASP.NET example with Visual Studio 2010:

·
I have a simple database table with a timestamp column;

·
I created a "Linq to SQL Class", and drag the table from Server Explorer onto it;

·
I dragged a LinqDataSource onto the web page and pointed it to the dbml;

·
I dragged a DetailsView onto the web page using the LinqDataSource.

·
I enabled editing on the data source.

When I run, the time stamp column is also displayed on the DetailsView as something like "AAAAAAAAB9Y=". Then, when I change the "EmployeeName" and update, I got following exception: Failed to set one or more properties on type person. Cannot convert value of parameter 'tstamp' from 'System.String' to 'System.Data.Linq.Binary'. I was strictly following the MSDN walkthrough. I tried multiple times, I even installed Visual Studio 2010 SP1 Beta. But it consistently through this exception. Can someone shed some light on this? Not a encouraging start form someone thinking to learn the lastest Microsoft stuff!

I was following a MSDN walkthrough, which is a very simple ASP.NET website with Visual Studio 2010: I have a simple database table with a timestamp column;I created a "Linq to SQL Class", and drag the table from Server Explorer onto it;I dragged a LinqDataSource onto the web page and pointed it to the dbml;I dragged a DetailsView onto the web page using the LinqDataSource.I enabled editing on the data source.When I run, the time stamp column is also displayed on the DetailsView as something like "AAAAAAAAB9Y=".Then, when I change the "EmployeeName" and update, I got following exception: Failed to set one or more properties on type person. Cannot convert value of parameter 'tstamp' from 'System.String' to 'System.Data.Linq.Binary'. I was strictly following the MSDN walkthrough. Can someone shed some light on this? Not a encouraging start form someone thinking to learn the lastest Microsoft stuff!dfsaf

View 1 Replies

ADO.NET :: Change Connection String Of Linq To Sql Entities?

Sep 9, 2010

I have a solution which uses Linq to SQL Data Classes to acced the db. I have a project for my domain objects in my solution, which is a class library and has the dbml file. When I set up the dmbl using the wizard, Visual Studio created anapp.config file on that project with the connection string. It also creatting asettings file with the same info. I've noticed that if I change the connection string in the settings file, the app.config gets updated, which is the expected behaviour.

However, I'm having a problem when I deploy my web site to the production server. I already set the app.config file's Build Action to "Content", and also set Copy to ouput directory to "Always". Nevertheless, when I install the web site and change the connection string in the app.config file, it still takes the old connection string, so obviously I get an error. I've found that it only works if I change it with in Visual Studio and then compile, but of course that's not an optimal solution, because any change in the production db server would mean I have to change my project's assembly, thus generating a new version.

What do I have to configure so that the assembly takes the connection string form my app.config file directly after I deploy?

View 9 Replies

DataSource Controls :: LINQ,C# Conditional Where With String.Contains...

Sep 22, 2010

I'm trying to find a way to do the following psudo:

void foo(int iArea, int iCity)
{
using (myDataContext context = new myDateContext)
{
var query =
from ad in context.Ads
join publisher in cintext.Publishers on ad.PublisherID equals publisher.ID
select new

[code]...

I can't find a way to do the check if the area code(iArea) is contained iside the string of the adArea from the DB.

View 3 Replies

ADO.NET :: Entity Framework - How To Join Tables Without LINQ And With Only String

Sep 30, 2010

I have a question about Entity Framework. answer if you know answer on this. I have such query :

[Code]....

Particularly I want to join few tables in one query, but I can NOT use LINQ and can NOT use ObjectQuery with objects mapped to DB fields inside my query. Because each entity creates dynamically. So this is what i

can NOT use : [URL]

The question is can I use something like this instead of using objects?

[Code]....

The purpose is to use Join method of ObjectQuery with syntax as in Where method :[URL]

View 2 Replies

Linq - QueryExtender Parameter Date Format String?

Mar 14, 2011

I would like to use QueryExtender control to retrieve records in a given date range.

<asp:QueryExtender ID="qeFilter" runat="server" TargetControlID="EntityDataSource1">
<asp:RangeExpression DataField="Date" MaxType="Inclusive" MinType="Inclusive">
<asp:ControlParameter ControlID="txtFrom" />
<asp:ControlParameter ControlID="txtTo" />
</asp:RangeExpression>
</asp:QueryExtender>

The problem is that date in text boxes is in "d.M.yyyy" format. I am unable to figure out how to specify the format for the asp:ControlParameter.

View 1 Replies

C# - How To Load An Existing Connection String For Linq To SQL From An App.config File

May 25, 2010

I'm running into a really annoying problem with my Linq to SQL project. When I add everything in under the web project everything goes as expected and I can tell it to use my existing connection string stored in the web.config file and the Linq code pulls directly from the ConfigurationManager.

This all turns ugly once I move the code into its own project. I've created an app.config file, put the connection string in there as it was in the web.config but when I try to add another table in the IDE keeps forcing me to either hardcode the connection string or creates a Settings file and puts it in there, which then adds a new entry into the app.config file with a new name.

Is there a way keep my Linq code in its own project yet still refer back to my config file without the IDE continuously hardcoding the connection string or creating the Settings file? I'm converting part of my DAL over to use Linq to SQL so I'd like to use the existing connection string that our old code is using as well as keep the value in a common location, and one spot, instead of in a number of spots.

Manually changing the mode to WebSettings instead of AppSettings works untill I try to add a new table, then it goes back to hardcoding the value or recreating the Settings file. I also tried to switch the project type to be a web project and then rename my app.config to web.config and then everything works as I'd like it to. I'm just not sure if there are any downfalls to keeping this as a web project since it really isn't one. The project only contains the Linq to SQL code and an implementation of my repository classes.

My project layout looks like this

[code]....

Every time I try to make the default constructor look like the first way, it always auto changes back to the second way once I make a change to the file unless the DBML is inside of a web project.

View 2 Replies

DataSource Controls :: Returning String Value Using Stored Procedure And Linq

Feb 7, 2010

I am having problems returning a string value through a stored procedure/linq to a label. Everything works fine if I return an integer value but I cant get a string value to bind to a label. I get the error message

Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value,
NumberFormatInfo NumberFormat) +201
Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) +66
[InvalidCastException: String "System.Data.Linq.SqlClient.SqlPr" to 'Integer' is invalid‚]

This is the stored procedure
ALTER PROCEDURE test
AS
Select ProductName
From Products

This is the vb page
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim db As New DataClassesDataContext
Dim product As Integer = db.test.ToString
Label1.Text = product
End Sub

This is the aspx page
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</form>

View 1 Replies

DataSource Controls :: Common Connection String In LINq To SQL Files?

Feb 20, 2010

I am using LINQ to SQL files in my class libray since every LINQ to SQL sources file is a seprate file and i have to set database connection string in each class library. Now, i have total 7 class libraires in my project how connection string be passed from web.onfg to LINQ file, so that i don't need to manually change the connection string. lke we did in asp.net 2.0 using connection string property in class file library.

How could we pass the same in LINQ's designer file.

View 4 Replies

DataSource Controls :: Returning Single String Value Using Linq And Stored Procedure

Jun 21, 2010

I can return single integer values when using stored procedures with Linq but I cant get single string values returned.

View 2 Replies

DataSource Controls :: Update Table Field With LINQ To SQL And Query String

Jul 11, 2010

I am trying to update my table ARTICLES and it has a field COUNTER, Everytime a user enter this ARTICLES, the page_load event runs a LINQ to SQL query taking the QueryString as parameter, increasing the COUNTER field in 1.

[Code]....

View 2 Replies

Forms Data Controls :: Append Two String Fields To Display In Gridview Using LINQ

Feb 4, 2011

I need to display Name1 and Name2 in a single column in gridview. I am using Linq. How is this done.

View 2 Replies

Visual Studio :: Linq To Sql Won't Let Me Select Connection String "None" Option?

May 19, 2010

I've noticed that VS2008 removes the "none" option in the properties -> connection dropdownlist after you have modified a LinqToSql class where the "none" option was previously specified.So if i create a LinqToSql class, drag some db tables in, then set the connection to "none" in the properties window, save, then make a change to the db tables i've dragged into the class, i can't get it to go back to "none" again.I've noticed this behavior sporadically, not all the time. Havent isolated when it happens yet.The none option is required if you want to save your connection string in the web.config, and not in the designer.cs class or the .dbml file.

View 2 Replies

ADO.NET :: LINQ To Entities Doesn't Recognize The "Int32 Parse(System.String)" Method

Dec 14, 2010

I am using Entity Framework to contact my data base. as part of my web code I am using Linq to entities, and I want to determine the number of elements in an anonymous type list. I can't get it to work, I get the exception: "LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method, and this method cannot be translated into a store expression."

var questItem = from chapters in context.TestChapter
from questions in context.Question
where chapters.ID == int.Parse(Request.QueryString["id"])
where questions.TestChapterID == chapters.ID
select questions.ID;
int numOfSteps = questItem.Count();

how can I get it to work?

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved