 |
|
 |
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
I have a problem regarding Linq to XML. I will try to explain my problem on a simple example. My Xml looks like:
<variables> <variable> <name>A</name> <type>int</type> <value>11</value> <variable> <variable>
In my code I have a method which returs all variables
// Variable class public class Variable { string name{get;set;} Type DataType{get;set;} object Value{get;set;} }
//Method which reads XML file public List<Variable> GetVariables() { var records = from record in document.Descendants("Variable") select new Variable { Name = (string)record.Element("name"), DataType = Support.GetType((string)record.Element("type"), DefaultValue = Support.Convert((string)record.Element("value"), Support.GetType((string)record.Element("type")) //???????? }; //Convert to List and return }
In the method GetVariabes() I call two methods, which are defined in the static class Support. The first one constructs a Type object from type name and the second one converts the string to type which is specified by second parameter. In the example above, I get the second parameter from another call to method Support.GetType() even though the parameter was set in the previous line(Property DataType in the variable class). Is it possible to get the DataType from previous line - so the problematic line woule look something like:
DefaultValue = Support.Convert((string)record.Element("value"), DataType)
Any advice will be appreciated,
Thank you for your help
Uros
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
hi guys
through linq to sql it generates all the table classed in the same class (file) and also the related method CRUd in the same file as well , is there any way that we can generate seperate class for each data table and all the table classed in a seperate library and the data base operations in another library , thansk.
Tauseef A Khan MCP Dotnet framework 2.0.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
hi guys i have two tables tablea(PK) and tableb(FK)
now i just want to load only data from tablea not from tableb but when i do
var qry = from result in con.tablea select result;
return qry.tolist()
but it gives me also the data from tableb , althoug when i see the sql query from con.log i just see it getting data from table a , why is that? if the query is pointing to just tablea so why there are records from tableb?
thanks.
Tauseef A Khan MCP Dotnet framework 2.0.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
You only should get the foreign key of tableb! according to your example... unless you've selected some data of tableb like result.tableb.fieldOfTableB <--- this automatically makes a join in your query! 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
i am using a three tier architecture , while in my dal i generate it from sql to link generator , so in this way my user interface can directly reference to my dal generated although i am calling dal from my middle layer , am i following the wrong approach ?
my user interface sholuld just know only my domain objects and my middle layer but its not in the case of linq ? why ?
Tauseef A Khan MCP Dotnet framework 2.0.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Tauseef A wrote: ut its not in the case of linq ?
Yes, it is still the case with Linq. Your implementation and understanding is incorrect. Adding Linq to SQL or Entity Framework does not negate a properly implemented nLayer architecture.
Your presentation layer should only know about the entity objects, either via DTOs you create at the business layer or self contained Entity objects produced by EF. To remain loosely coupled the presentation layer should not make direct calls to the data layer, or have any knowledge of it.
I know the language. I've read a book. - _Madmatt
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
how ?
when we generate classes so it generates all the dto's and its data base methods in the same class or same library , so how is that possible that we can make these operations hide from UI layer ?
can you please give me any example reference .?
Tauseef A Khan MCP Dotnet framework 2.0.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
You are mistaken. Using EF the entitites are created with properties corresponding to the columns in the database table. There are no methods for accessing the database from these entities. Access is via the ObjectContext implementation which has an overloaded constructor that accepts a connection string. You can create a instance of this class in your data layer.
I know the language. I've read a book. - _Madmatt
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
but these dto's and datacontext operations are created in the same class library so we can refer all the stuff from the UI .
rite ?
Tauseef A Khan MCP Dotnet framework 2.0.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Don't allow the ObjectContext to be created outside of the layer you wish it be used in. EF is complex but your making it to be more complicated than it is.
I know the language. I've read a book. - _Madmatt
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Don't allow the ObjectContext to be created outside of the layer you wish it be used in. ?
Tauseef A Khan MCP Dotnet framework 2.0.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Hi,
I am trying to delete my SQL Compact FIXMsgs Table upon application startup.
DevelopmentDB db = GetNewDataContext(); PerformanceTimer timer = new PerformanceTimer(); int nbFIXMsg = 0; if (_log.IsDebugEnabled) { nbFIXMsg = db.FIXMsgs.Count(); timer.Start(); } //db.ExecuteCommand("delete from FIXMsgs"); db.FIXMsgs.DeleteAllOnSubmit(db.FIXMsgs); db.SubmitChanges(); if (_log.IsDebugEnabled) { timer.Stop(); _log.Debug("ClearDataBase - " + nbFIXMsg + " messages deleted in " + timer.MilliSeconds + " ms"); }
Using db.FIXMsgs.DeleteAllOnSubmit(db.FIXMsgs); -> 4000 items deleted in 40,000 ms!
Using db.ExecuteCommand("delete from FIXMsgs"); -> 4000 items deleted 250ms
it's about 200 times faster!
I clearly am missing something obvious as such a performance difference is ridiculous.
Can you please try an help me to figure out what I'm doing wrong?
Thanks,
Regis
PS: a few more information - I am using sqlMetal to create the dbml file - This table has a primary key
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
You are not doing it wrong. Linq is generating a delete statement for each row in the table and matches the row to delete on all columns. This is why it takes a lot of time.
the ExecuteCommand is the prefered way in this scenario
Andreas Johansson
IT Professional at Office IT Partner i Norrbotten Sweden
What we don't know. We learn. What you don't know. We teach
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
I am trying to create an N-tire windows application using the ADO.net Entity framework. If I use Entity framework will my application be database agnostic. My application will be used with sql server compact edition and when I need to scale up I need to use the application with Sql server 2008 express edition. How much additional work will be involved if I need to accomplish the above?
Pointers and references in this directions will be deeply appreciated.
J.Anandarajeshwaran WWW.BeginWithDisbelief.com
hi hi hi hi
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I am very new to the linq to sql getting proble when I am tryig to insert the record in a table as the table do not have any primary key.
Thanks Sri...
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
What error are you getting? Are you aware that Linq to SQL is obsolte and Entity Framework is the successor?
Best wishes, Navaneeth
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
hi Navaneeth, thanks for making reply.
I am getting following error "Can't perform Create, Update or Delete operations on 'Table(TestTable)' because it has no primary key. " Code is as follows: TestTable test = new TestTable(); test.NAME = txtNametest.Text; test.ADDRESS = txtaddrtest.Text; db.GetTable<TestTable>().InsertOnSubmit(test); db.SubmitChanges();
I google the problem but did not find any solution as per different forum we need to add a addition column (may identity) to set as primary key. but I don't think Its good practice to add extra column.
Please suggest how should i go ahead.
Thanks, Sri...
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
just open the DBML-file in design mode and multi select the columns that you wand to set as primary key. for example NAME and ADDRESS.
Then it will work!
it is very NOT good practice to have tables i a database without a primary key!!
kind regards
Andreas Johansson
IT Professional at Office IT Partner i Norrbotten Sweden
What we don't know. We learn. What you don't know. We teach
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
 |
Thanks Andreas, Its working fine. its good, we can set the primary key on the entity level not in the database.
thanks, Sri...
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
hi i'm having problem with linq query...
this is what i have var query = from venue in db.Venues select venue; query = query.Where(q =>; SqlMethods.DateDiffDay(q.ExpiresDate, DateTime.Now) == 7); query = query.Where(q =>; q.IsDisplay).OrderByDescending(q =>; q.ExpiresDate);
what i want is to populate venues which are expired 7 days from todate..but date formats are different of q.ExpiresDate and DateTime.Now.
how to solve this problem...is thr anyway that i can format datetime.now to expiredatetime...
need help urgetly...
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
why are you not doing the whole query as LINQ?
var query = from venue in db.venues where venue.IsDisplay && DateTime.Now.Subtract(venue.ExpiresDate).TotalDays == 7 select venue;
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |