Lets say I have a simple table that only contains two columns:
MailingListUser
- PK ID (int)
- FK UserID (int)
I have a method called UpdateMailList(IEnumerable<int> userIDs).
How do I, in LINQ, make inserts for the userIDs that are present in the passed in parameter but don't exist in the db, delete the ones that are in the...
Hi I am trying to use a Repository Pattern with Linq To Sql
I am using some of the code from here(http://mikehadlow.blogspot.com/2008/03/using-irepository-pattern-with-linq-to.html)
T GetById(int id); is the repository method, I am interested in.
Inside the codebase, it converts the int id passed to lambda expression(p => p.Id == Id)...
Hello every one, I'm using linq to SQL and when I run this query
var lstData = from s in dataTrackDB.datas
join m in dataTrackDB.mkts on s.mktcode equals m.mktcode
join n in dataTrackDB.mktnews on m.mktcode equals n.oldmktcode
select new data
...
I have an table called Invoices with a column named Vendor. The Vendor column is a FK reference to a Vendors table with the PK being Id.
My dbml creates the appropriate objects...Invoice and Vendor. However, my Invoice object has both a Vendor property (as a String) and a Vendor1 property (as a Vendor object).
I thought it would have t...
I'm been working on a GetRuleViolations() method for my User class, but I'm getting a little hung up on on something:
What happens when different actions require different business rules?
My User table has the following columns: Id, UserRoleId, Username, and Password. Several actions involving User are possible (create new user, edit u...
I am getting the following error on production server.It works well on localhost.
Error: Sequence contains more than one element
...
I'm about to show my inexperience here, but hey - like any developer I want to learn.
Given the following interface:
public interface IRepository
{
entityDB Database { get; set; }
IQueryable<T> All<T>() where T:class, new();
T Single<T>(Expression<Func<T, bool>> expression) where T : class, new();
IList<T> Find<T>(Expr...
Hi,
I have a simple form which inserts a new Category with the given parentID (ServiceID).
and my parent child relationship is this;
Service > Category
my url for creating a Category based on the ServiceId is this
/Admin/Categories/Create/3 => "3 is the serviceID"
and my Action method is this
[AcceptVerbs(HttpVerbs.Post)]
pub...
If I add properties onto a linq entity (employees for example), that simply refer to other properties to implement an interface, return an IQueryable, and the where clause mentions those added properties that just point to other linq entity properties, will it cause the entire table to be loaded and filtered in memory instead of at the s...
Employee is a sample entity type.
var r1 = (from c in _ctx select c).Skip(5).Take(5);
// my intent is to pull the first record from the query
var r2 = (from c in _ctx select c).FirstOrDefault<Employee>();
// my intent is to pull the last record from the query.
// any good way to ask for the result back in the reverse
// orde...
I'm interested in the side effects and potential problems of the following pattern:
CREATE PROCEDURE [Name]
AS
BEGIN
BEGIN TRANSACTION
BEGIN TRY
[...Perform work, call nested procedures...]
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
RAISERROR [rethrow caught error using @ErrorNumber, @ErrorMessage, ...
Wondering if there is a good way(generic method which is) that can dynamically add child entity to appropriate entity set of a parent. Right now I have to do something like this, and it's not very elegant:
public int AppendChild<T>(PATIENT patient, T child)
where T : EntityBase
switch (typeof(T).Name)
{
cas...
I have a Linq to SQL class.
There is a one to many relationship in my database.
The relationship maps correctly in the designer, and an EntitySet<> property is created in the designer.
When I run the code, the EntitySet<> does not populate with any data, even though there are associated records, they do not populate into the EntitySet...
I have a Linq to SQL EntitySet with a Foreign Key Relationship between two tables. The tables in question are a Task table (called Issues) and a Departments Table. The foreign key is the department name (Which is guaranteed unique). I am running into an issue in that you cannot change a Linq to SQL FK field if the corresponding data is l...
I'm trying to find a way to generate Linq to SQL classes with bi-directional serialization attributes. Basically I want a DataMember tag (with an appropriate order) on every association property, not just the ones where the class is the primary key (like the Visual Studio generator and SQL Metal do). I checked MyGeneration, but didn't re...
What's the right syntax for this?
var words= from h in db.Words
orderby(a => Guid.NewGuid()).ToList()) //error
select h;
var words= from h in db.Words
orderby((a => Guid.NewGuid()).ToList()) //error
select h;
var words= from h in db.Words
orderby...
I'm struggling to come up with the right words to summarize this problem, so any input on what I can add to clarify it would be appreciated.
The basic scenario is this: I have a basic CMS (with pages, users, etc.). Page is a LINQ data object, which maps directly to a Page table.
I've added a method to the Page class called GetUserPerm...
Is there a way to do an insert/select with Linq that translates to this sql:
INSERT INTO TableA (...)
SELECT ...
FROM TableB
WHERE ...
...
I am fetching data from database to textbox using Linq.When i try update the same textbox value,it does not work.
DAL.TournamentsDataContext tdc = new SchoolSports.DAL.TournamentsDataContext();
var tournamentTable = tdc.GetTable<DAL.Tournament>();
var tournamentRecord = (from rec in tournamentTable
...
I need to read in XML data posted from external systems, which will be formatted roughly as follows:
<Applicant>
<FirstName>John</FirstName>
<LastName>Smith</LastName>
<Address>12 Main St</Address>
</Applicant>
This is a direct mapping of my Linq to SQL Applicant class, excluding a few properties.
What's the best way to deseria...