Active Record Collection with Subsonic [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I wish to make all my save transactions at the same time.
I'm using Subsonic 3.0 with active record. I've seen some post with MyClassCollection.Save();
However when i "Run Custom tool" i don't get collections. Obviously i'm missing a trick here?
There is of course another way to do this, using BatchQuery. I had an issue with this. Appreciate any thoughts, as you can see i've very new too all this.
var provider = ProviderFactory.GetProvider("MyProvider");
var batch = new BatchQuery(provider);
foreach (var cdnEntry in cdnEntries)
{
var query1 = new Insert(provider).Into<Clip>
("Author").Values(
cdnEntry.Author);
batch.QueueForTransaction(query1);
}
batch.ExecuteTransaction(); // nothing happens as query count alway = 0

I obviously need to read on the different patterns available for subsonic. Tho i have got the batchquery working. The above code works. I had few silly sql typo's giving me grief.

Related

Predicate matching a list [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm trying to do something like -
List<int> accountList = new List<int>();
accountList .Add(1);
accountList .Add(27);
var rec = _db.Accounts.Where(a=> accountList.Contains(a.accountId)).Take(10);
My code is a little more complicated than this - there are several other conditions in the where clause, but this is the bit that is causing problems - nothing gets returned even when there are matching values.
Basically I want it to retrieve all the records where accountId matches a value in my list.
Any pointers?
The sample above is giving me a cant convert lambda error.
You are missing a bit on your contains version
var hold2 = _db.Accounts.Where(a => find.Contains(a.accountDd)).Take(10).ToList();
Have you tried using any
var hold2 = _db.Accounts.Where(a => accountList.Any(m => m == a.accountId)).Take(10).ToList();

How can I improve this nested loop? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am trying to do a fuzzy match of records in two Account table using .NET Entity Framework.
I wrote some code like this but it has bad performance like 1 min a record.
ARSalesforceEntities arsf = new ARSalesforceEntities(); //dbcontext
Salesforce_FFEntities ffsf = new Salesforce_FFEntities(); //dbcontext
var araccounts = arsf.Accounts; //dbset contains 400000 records
var ffaccounts = ffsf.Accounts; //dbset contains 6000 records
IDCONV byName = new IDCONV();
IDCONV byAddress = new IDCONV();
foreach (var ffaccount in ffaccounts)
{
Console.WriteLine(++count);
foreach (var araccount in araccounts)//this line goes every slow like 1 min
{
Basically, I am comparing the records in two tables with complicated logic.
How can I greatly improve the performance of the code?
Thank you
This line:
var ffaccounts = ffsf.Accounts;
is what's hitting you hard. You're basically assigning the IQueryable to a variable which, when accessed in your inner loop, re-queries the database everytime. I imagine simply adding ToList() on the end will drastically improve your performance:
var ffaccounts = ffsf.Accounts.ToList();
That's assuming of course that it's acceptable to materialise the 6000 rows into memory.
If not, then you might want to consider writing the logic in SQL and doing all the work in the DB instead...

Web service WHERE / ORDER BY (?) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a web service that returns the list of all the clients.
I can get the list into a gridview by calling the method get all data like this.
test.RH_WebServiceService ligar = new test.RH_WebService();
test.baseList[] data = ligar.getAllData();
The thing is I wanted to filter it by name (for example) I've been reading online and people have said to me that I can just do it like this:
test.baseList[] data = ligar.getAllData().Where(condition);
However I can't get it to work. Do you guys have any ideas?
Assuming you are using Linq then you can just do:
test.baseList[] data = ligar.getAllData().Where(d => d.Name == "John");
The d is a random letter given to the object. Name is what i am assuming your property is called. Although i would recommend creating a method in your service that you pass the name in and get back the filtered data. That way you only return data you need which will improve performance. Something like this:
test.baseList[] data = ligar.getDataByName("John");
Maybe this will help some:
test.baseList[] data = ligar.getAllData().Where(f=> f.field == "value").ToArray();

how to use StreamReader in C# to read only entries over a specific length to a list? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
when using StreamReader in C# to load a txt file into a list, i assume that using a simple "If" the string's length is over a particular length, it will add it to the list. can anyone provide C# code for this? this IS homework, but it's NOT a C# class. the instructor would gladly provide this if i asked this specifically. thx.
the txt file is a dictionary of ~280,000 words, one per line. very simple move to turn into a list, but i'm wondering about getting words at least 2 characters long.
Just use LINQ to give you a subset.
List<string> lines = File.ReadLines(filename)
.Where(l => l.Length > specifiedWordLength)
.ToList();

.Net how to play audio in the root of the website with System.Windows.Media.MediaPlayer() [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I use this code blow in .NET. It works fine. The problem is that I want this audio to play in the root of the website. What changes should I make for this? Thanks
var sample= new System.Windows.Media.MediaPlayer();
sample.Open(new System.Uri( #"D:\voices\1.wav");
sample.Play();
In a web application, this might look something like this:
sample.Open(new System.Uri(Server.MapPath("~/") + #"\voices\1.wav");
I say might because that all depends on whether or not the voices folder exists in the root of the website. Additionally, you should probably leverage Path.Combine instead:
var path = Path.Combine(Server.MapPath("~/"), "voices", "1.wav");
sample.Open(path);
Finally, I don't know what sample is, but the Open method may not work in a website. I'm making the assumption you know what Open does and whether or not it can work in a website.
Use server.mappath("~/") <- that's the filesystem root for your website.
dim path as string = server.mappath("~/") & "/voices/1.wav"
Note that backslashes, for filesystem path, not URI.
Hope it helps.

Categories