Saving Lists to tables in subsonic 3.0 - subsonic

I have been using subsonic 2.0 but have moved to subsonic 3.0
I want to create a list of my parent child objects and save in a batch rather than .Save() on each object
In subsonic 2.0 you could use batchsave() but I also want to do a deepsave() on each object to populate the relationships of the parent to child tables
Is this possible - and does someone have example code

Related

What is the best way to add tables to Entity Framework 6 Code First to Existing Database?

I'm developing an ASP.NET MVC 4.5 project using EF 6 Code First to an Existing Database. I would like to create some new tables with foreign key relationships to one of the tables in the dbcontext I've created. I've altered and added columns in that original table, creating several migrations. There is real data in that table.
I would prefer to create the new tables in the database, but don't see how EF would generate a model for me. I can code the model myself, but don't see any documentation about how I would add it to the context class generated by EF. And then the migrations would be out of whack.
So I'm thinking that the best thing to do would be to delete all the migrations, delete the context class and drop the migrations table. Then I could start from scratch with an initial migration. Am I missing some gotcha? Is there a better way?
FWIW to others facing this dilemma, I figured it out. First I got rid of all the migrations, following the 100+ up-voted answer here: Reset Entity-Framework Migrations
Second, I created new the tables and constraints I needed in the database.
Third, I created a new entity in my solution and generated model classes from the database. I changed calls from the old entity to the new entity.The generator overwrote the model for the original table, but since I have all the annotations in version control, it is trivial to paste them in.
If I need to, I can enable migrations again.
Hope this helps.

Linq to Sql using a non-column attribute property in Association attribute

I am trying to create an association between 2 linq to sql entities, say Entity A and Entity B.
A uses a non-column attribute property ( named BaseDocumentType ) and a column attribute in an Association for "ThisKey" and 2 column attributes for "OtherKey". The following is an example of my Association attribute definition...
[System.Data.Linq.Mapping.AssociationAttribute ( ... ThisKey = "BaseDocumentType, Column2" , OtherKey = "Column1,Column2" )]
When I run it I get the following error...
"Data member 'System.String BaseDocumentType' of type 'Library' is not part of the mapping for type 'A'. Is the member above the root of an inheritance hierarchy?"
How can I define the relationship using the non-column attribute property or how do I make this work?
Thanks.
The message is quite clear. LINQ to SQL translates statements to SQL and you tried to use a property that doesn't map to a column, so it can't be translated to SQL.
You'll have to retrieve the entities you want from the database then try to query them using LINQ to Objects, ie LINQ operations on the resulting lists or arrays. A better option is to rethink your design and find a way to retrieve only the data you need from the database and avoid processing the results on the client.
Linq to SQL in this case prevented you from doing something really dangerous. It could have retrieved all the data and process them using your non-column attribute but that would create an enormous performance hit. Some naive LINQ providers actually do just that. Imagine retrieving 1000 objects from the database only to find the two objects that match over this non-column attribute.

Subsonic how do I filter a loaded collection?

Currently I am using Subsonic 2.1 and .NET 2.1 and I have an issue where I am attempting to filter a pre-loaded collection with 300+ items. I am using the following to attempt to preform the filter:
orders = MasterOrders.Where("account", mbrAccount).Load();
The end results is setting orders equal to the entire MasterOrders collection and not the filtered results. Any suggestions?
If you're targeting Dotnet Framework 3.5 you can use a LINQ select-query. Then convert it to a List<MasterOrder>.

Subsonic 2.2 InnerJoin Across Two Databases

Can anyone provide an example of how to join across two schemas using subsonic 2.2.
This doesn't work:
SqlQuery qu = new Select("*")
.From(NorthwindLeads.Lead.Schema)
.InnerJoin(Northwind.StatsMap.SourceIdColumn, NorthwindLeads.Lead.SourceIdColumn);
There's no easy way to do this in subsonic that I'm aware of. I would recommend adding a view to your database which returns the data you want from the other schema and then joining to the view in your subsonic query.

Is there deep loading in subsonic?

I am new in subsonic, and can't find the way to load data whith it's parents or childs data in one query. Is it possible in subsonic?
Basically no SubSonic 2 does not support deep loading. It is possible in SubSonic 3 using IQueryable however. See the following post for more:
Subsonic Deeploads: Is This Supported?
You CAN do it with subsonic 2. Make a partial class with the same namespace and class name.
Then create a property that loads the data when it is called.

Resources