 |
|
 |
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers, Chris Maunder
The Code Project Co-founder Microsoft C++ MVP
|
| Sign In·View Thread·PermaLink | 5.00/5 (2 votes) |
|
|
|
 |
|
 |
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers, Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
 |
Hi, how to Get Database Schema/Structure in DataSet with complete Constrain, and Relationship. I have parent,Child table in Database.These table have relationship how to get these tables schema with relationship ?
ali
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
code is:- protected void ImageButton2_Click(object sender, ImageClickEventArgs e) {
MA_TECHDataContext ma10 = new MA_TECHDataContext();
var validity = from c in ma10.customer_infos where c.customer_lname == TextBox2.Text.ToString() select new { c.customer_lname, c.customer_ID };
GridView1.DataSource = validity; GridView1.DataBind();
// TextBox4.Text = Convert.ToString( validity.Single() );
Array ab;
ab = validity.ToArray();
TextBox4.Text = ab.GetValue(0).ToString();
well the result in txtbx is :-- { customer_lname = 222 , customer_ID = 2 }
yes in curly brackets and all one!!!!!!!!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
There is nothing complicated about it. You are creating an anonymous type, that's how it will display.
BTW, TextBox2.Text is a string, you don't need to do TextBox2.Text.ToString(). It's just stupid to do it.
I know the language. I've read a book. - _Madmatt
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
wallaq wrote: thanks but i know!!
What do yo know?
wallaq wrote: how to get it display correctly
Define "correctly".
I know the language. I've read a book. - _Madmatt
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I have a collection that inherits from IEquatable. It has numerous properties all of which are compared if they are filled. Now however comes the curve ball.
I take the collections and use 'Exclude' to obtain differences. I had in mind original how to handle my issue but at the time I was not really aware of the HashCode.
The issue is that instead of just a straight comparison of all properties, a few of the properties must be conditional checked for ranges.
For example, 2 of the properties are X and Y. A Range of (10, 200) is put in for the items being equal. So assuming all other properties are equal and given the following data set: 100, 2000; 110, 2200; 140, 2000;
We would say that the first 2 are equal but the last is not. That is the issue put simply. There is a conundrum though, 100, 2000; 110, 2200; 120, 2400;
In this last case the first 2 are equal and the last 2 are equal. However the first is not equal with the last. This can ofcourse be addressed in the 'Equals' call by adding ranges to the comparison. However, how can this be addressed in the GetHash code? If 2 items are equal they MUST return the same hash code right?
This does not seem possible because of the later case.... What do I do?
"9 Pregnent woman can not have a baby in 1 month" -Uknown
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Reference: http://msdn.microsoft.com/en-us/library/bb300779.aspx[^]
The comments in the code using GetHashCode state // If Equals returns true for a pair of objects, // GetHashCode must return the same value for these objects.
Does this mean that if the equals returns they are NOT the same it is OK for GetHashCode to return the same value?
If this is true then my GetHashCode override can just ignore the paramaters that require ranges and only the Equals will account for them.
Can someone throw me a bone here and let me know if this is correct?
"9 Pregnent woman can not have a baby in 1 month" -Uknown
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
My Testing shows this is the case but if anyone knows anything I am missing I would be interested to hear it.
"9 Pregnent woman can not have a baby in 1 month" -Uknown
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
You should consider something other than Equals for your situation. You correctly noted the HashCode and Equality linkage, but you seem to have missed the restriction on Equals that if a = b and b = c then a = c, which your proposed usage of Equals will not implement. I would suggest that you give the comparison method another name such as IsNear. That method could then take the "nearness range" as parameters if desired.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Well it is that I am actually using Linq's 'Except' method which uses Equals and GetHashCode.
I would rather not loop through every data point doing a comparison to every data point to determine IsNear. Except made the most sence but maybe there is something else I could do...
Suggestions?
"9 Pregnent woman can not have a baby in 1 month" -Uknown
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I would recommend making an IEqualityComparer class and passing that to the Except method instead of implementing Equals and GetHashCode directly on your object. If you do it that way, the violation of the Equals contract (a = b and b = c but a <> c) is limited to when you explicitly use the "NearEqualityComparer". One side effect of Except is that it will essentially do a "Distinct" on the first second sequence as well as filtering out those in the second sequence before filtering the first sequence. This could cause some points from the second sequence to never get compared to any in the first sequence. It will also do a "Distinct" on the first sequence during filtering. If you did ({1, 1, 2, 3, 4, 5}).Except({4, 5}) you would get {1, 2, 3}
You are correct in noticing that a.GetHashCode() = b.GetHashCode() does not imply a = b. In fact, for objects that have no immutable properties that still want to implement =, returning the same value for all instances from GetHashCode is one way to meet the requirements. Of course, this comes with the tradeoff that Dictionary and HashSet (which Except uses) performance is trashed.
The NearEqualityComparer would look something like below (where MyClass is your data object type). The better the GetHashCode, the fewer Equals comparisons will have to be checked by Except.
Public Class NearEqualityComparer Implements IEqualityComparer(Of MyClass)
Public Function ComparerEquals(ByVal x As MyClass, ByVal y As MyClass) As Boolean _ Implements System.Collections.Generic.IEqualityComparer(Of MyClass).Equals Return ComparerGetHashCode(x) = ComparerGetHashCode(y) AndAlso _ x.IsNear(y, range arguments here) End Function
Public Function ComparerGetHashCode(ByVal obj As MyClass) As Integer _ Implements System.Collections.Generic.IEqualityComparer(Of T).GetHashCode End Function
End Class
EDIT: Fixed information about how Except works
modified on Friday, November 6, 2009 1:44 PM
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
 |
Hi All, I'm new to Linq.
I've got the following code to take two tables, and result in the rows from table1 that are NOT in table2. The Linq is out of the book <u>Pro Linq</u> from Apress.
Dim seq1 As IEnumerable(Of DataRow) = table1.AsEnumerable() Dim seq2 As IEnumerable(Of DataRow) = table2.AsEnumerable()
Dim except As IEnumerable(Of DataRow) = seq1.Except(seq2, System.Data.DataRowComparer.Default)
Dim Table3 As New DataTable Dim NewTableColumn As DataColumn = Table3.Columns.Add("UserName") 'For Each row resulting from LINQ query, add to new table. For Each dr As DataRow In except Dim NewRow1 As DataRow = Table3.NewRow() NewRow1("UserName") = dr.Item(0).ToString Table3.Rows.Add(NewRow1) Next
Obviously I don't understand something about Linq. When the page runs through the procedure for the first time, everything works. The variable "except" contains the correct rows. However, after binding and postback, though I've confirmed that Table1 and Table2 contain the correct rows, the linq doesn't respond as expected. It's as if it is doing nothing at all.
Any thoughts on this?
Thanks in advance!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Member 4125480 wrote: It's as if it is doing nothing at all.
This is weird.. There must be some problem with Datatables. Otherwise how it is possible..
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
I researched on google but couldn't find useful things. I' am using Linq To SQL and having trouble when using custom methods in LTS because custom methods can not be translated into SQL. My problem is;
i have a generic class and some generic methods in that class. One of the methods receive a string argument which is a property of an entity. I am using reflection to find property specified by a string argument. And i am getting properties value again via Reflection with PropetyInfo.GetVAlue(...) method. Because this method has no translation into SQL i have the translation excepiton. How can i solve this. I used LINQ trees, however no solution. My code is below. The error comes at the last line "pInfo.GetValue(x, null)" has no translation to SQL.
/// /// Summary : Gets entity from persistance storage - database - by the specified primary key value /// /// TPrimaryKey : Type of primary key /// PrimaryKey: The entity's primary key value /// Returns : Retruns the entity whose primary key value equals the specified by PrimaryKey argument
public virtual TEntity GetByPrimaryKey(TPrimaryKey PrimaryKey) { // Null checkings if (context == null) throw new ArgumentNullException("DataContext argument can not be null.");
System.Data.Linq.Table tableEntity = context.GetTable(); if (tableEntity == null) throw new Exception("There is no type of table specified." + typeof(TEntity).ToString()); // Initializing en example of the Entity Type to find PropertyInfo that is marked with System.Data.Linq.Mapping.ColumnAttribute attribute having value of IsPrimaryKey equals to true TEntity entity = new TEntity();
// Find the column that is marked with System.Data.Linq.Mapping.ColumnAttribute attribute having value of IsPrimaryKey equals to true. System.Reflection.PropertyInfo pInfo = this.FindPrimaryKeyColumnedProperty(entity); // If primary key property can not be found throw exception if (pInfo == null) throw new Exception("Property that is marked with System.Data.Linq.Mapping.ColimnAttribute attribute having value of IsPrimaryKey equals to true can not be found");
// Entities in the collection is compared with PrimaryKey value. If an entity has same primarykey value in its primary key marked property, the entity is returned. return tableEntity.Where(x =>; ((TPrimaryKey)pInfo.GetValue(x, null)).Equals(PrimaryKey)).Select(x => x).First(); }
I use this instead of last line but same error beacuse of propertyInfo.GetValue(...);
System.Linq.Expressions.Expression> exp = x => ((TPrimaryKey)pInfo.GetValue(x, null)).Equals(PrimaryKey);
return context.GetTable().Where(exp).First();
modified on Tuesday, November 3, 2009 10:39 AM
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
i have done it guys with expression. This article helped me
http://social.msdn.microsoft.com/Forums/en-US/linqprojectgeneral/thread/8b8f766c-c7a2-4b29-a075-2db80a65a0fe/[^]
i replaced the return statement to this ;
System.Linq.Expressions.ParameterExpression paramExp = System.Linq.Expressions.Expression.Parameter(typeof(TEntity), "ParamExp");
System.Linq.Expressions.Expression<Func<TEntity, bool>> predicate = System.Linq.Expressions.Expression.Lambda<Func<TEntity, bool>>( System.Linq.Expressions.Expression.Equal( System.Linq.Expressions.Expression.Property(paramExp, pInfo), System.Linq.Expressions.Expression.Constant(PrimaryKey)), paramExp);
return context.GetTable<TEntity>().Where(predicate).First();
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
 |
Just curious on people's opinions on this. When you find LINQ sample projects or tutorials on The Code Project, would you prefer that their sample databases use
- SQL Server 2008 Express, or - SQL Sever Compact Edition 3.5 (the one that comes with VS2008)?
I did a tutorial using 2008 Express but am thinking I should switch it to use Compact Edition because I think that would make it more accessible (people don't need to have also downloaded SQL Server 2008 Express) and also it means smaller downloads since the compact database files are smaller.
But, I just want a sanity check before I make this change to make sure this will be preferable for people.
Thanks! Abby
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Personally I like CE because I know very little about SQL butI can destroy and create CE databases fairly quickly, and LINQ seems to work well with it. Unfortunately a number of (very good) tutorials assume you have the MS Northwind database and Server 2008 already installed. I suspect that the thinking is that anyone using an SQL database is developing web sites or commercial apps so is more likley to need server 2008.
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
 |
Hi,
Can any body convert below sql query into LINQ for me please
SELECT ProjectCategory.ProjectCategoryName FROM ProjectCategoryDetails INNER JOIN ProjectCategory ON ProjectCategoryDetails.ProjectCategoryID = ProjectCategory.ProjectCategoryID INNER JOIN ProjectContentInfoSample ON ProjectCategoryDetails.ProjectID = ProjectContentInfoSample.ProjectID WHERE (ProjectCategoryDetails.ProjectID = 'Pr-11')
Many Thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi All,
I have resolved it myself
from p in ProjectCategories join b in ProjectCategoryDetails on p.ProjectCategoryID equals b.ProjectCategoryID join c in ProjectContentInfoSamples on b.ProjectID equals c.ProjectID where c.ProjectID == "Pr-09" select new { p.ProjectCategoryName }
Many thanks
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
 |
If you have defined the relationships in the data context (.dbml), linq has what i would say lazy loading intellisense which gives you a way to do complex query in a simple linq friendly way. Here is an example related to your query:
using (dataContext db = new dataContest) { var q = from p in db.ProjectCatergories where p.ProjectCategoryDetails.ProjectContentInfoSamples.ProjectID == "Pr-09" select new { p.projectCategoryName }; }
So basically linq joins the tables automatically and that is one of the reasons I believe linq is so powerful!
Hope this helps!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |