I'm playing with LINQ-To-SQL in .NET 3.5 and have built some classes based on an underlying database. I now face the decision: do I validate data in the class code, or in the database?
I can see pros and cons either way. If I do validation in the database, the validation takes place no matter what app is using the database. (I currently...
I am running into a problem where my CRUD operations on an entity sourced from an SQL View is not calling the generated methods for said operations.
Example:
I press "Delete" in a ListView on an item, connected to a LinqDataSource. It throws an error saying that it cannot perform the operation because it affects multiple base tables. T...
UPDATE
As Mathias notes below, this exact problem has been reported and resolved here:
ASP.NET-MVC (IIS6) Error on high traffic: Specified cast is not valid
ORIGINAL POST
This may be too specific a debugging issue to be posted here, but I'm posting it anyway in the hopes that it produces a solution that others find useful.
I have a w...
I have a property within a class, that I need to iterate through all the possible distinct IDs from a relationship.
I am within a User, which belongs to a Company. Companies, have many solutions and each solution has many "SolutionPortals". What I want, is a list of all distinct "PortalIds" from the "SolutionPortals" (SolutionPortal.Por...
I'm trying to use LINQ to SQL to select a few specific columns from a table and return the result as a strongly typed list of objects.
For Example:
var result = (from a in DataContext.Persons
where a.Age > 18
select new Person
{
...
I am trying to get a simple join query from 2 tables , they have no relationship , so far i got this code but there is an error that i dont get it , please help
var query =
from p in db.Productos
from s in db.Stocks
where p.Nombre == "Suaje" && p.TipoProducto == tipo
...
I have a scenario where I want to have a question object and users can concurrently add answer objects to the question object.
The question object needs to maintain the answer count.
How can I do an implementation in Linq2Sql that transactionaly saves the answer object that the user submitted to the question and updates the incremented...
I have a Customer class that contains a property, MyProperty, which is of a custom type MyCustomType. I want to persist the property value in the database as text. In the designer I've set the Type to 'MyType' and the Server Data Type to 'varchar(10)'. When I build the project I get the following error:
DBML1005: Mapping between DbTy...
so, i have a method: I'm counting a number in a sequence with holes, this number should be the first hole or max()
public static int GetRegisterNumber<T>(this IQueryable<T> enumerable, Func<T, bool> whereFunc, Func<T, int?> selectFunc)
{
var regNums = enumerable.OrderBy(selectFunc).Where(whereFunc).ToArray();
i...
I have an ordered sequence like {1, 3, 5, 6, 8, 9} I want to get first missing element(2 in the example) or max() if sequence contains no missing elements.
Now I'm doing it like this:
public static int GetRegisterNumber<T>(this IQueryable<T> enumerable, Func<T, bool> whereFunc, Func<T, int?> selectFunc)
{
var regNums = enumerable.Or...
LINQToSQL doesn't like my sproc. It says that the sproc has return type "none", which is probably, because I am using an sp_ExecuteSQL statement to produce the results.
The SQL Server Sproc Code
I have a stored procedure similar to the following
CREATE PROCEDURE Foo
@BarName varchar(50)
AS
BEGIN
DECLARE @SQL NVARCHAR(1024)
SET @S...
Hello,
I'm newbie at LINQ and I'd like to know how to use it with a database located on a remote server.
So, in other words...is there any way to tell LINQ my database's connection string?
Thanks,
Brian
...
In my organization we have to answer to a separate DBA group for decisions like using LinqToSQL . What do you see as some of the best reasons for using L2S rather than stored procedures.
...
I am using ASP.net MVC with C#
Why this is code :
public IQueryable<Product> ListProducts(string prodcutType)
{
var results = from p in db.Products
join s in db.Stocks
on p.ID equals s.IDProduct
where p.ptype == prodcutType
select n...
I'm running this query in LINQ:
var unalloc = db.slot_sp_getUnallocatedJobs("Repair",
RadComboBox1.SelectedValue, 20);
It runs when I first open the page, but when I go back to it and try to run the same query with a different value, "Con", being passed through, the linq to sql designer.cs tells me that I've got a t...
Hey,
I was wondering what the "correct"-way is when using a Linq to Sql-model in Visual Studio.
Should I create a new model for each of my components, say Blog, Users, News and so on and have all different xxxDataContext's with tables and SPROCs added in each of these.
Or should I create one MyDbDataContext and always work against that...
I asp.net mvc my model classes won't show up in the Add View dialog, so that VS automatically can generate CRUD views for them.
I have my Model classes (Linq-to-SQL) in a separate project (but in the same solution) than my asp.net MVC project.
Only stuff from the Elmah and Autofac namespace shows up in the list!
...
I have a small winapp that uses LinqToSQL as it's DAL. I am creating a summary view of all the CaseNotes for a given person and one of the fields is a Details box. I need to return only the first 50 characters of that column to my treeview function.
Any hints on how I do that? The below is how my TreeView function gets its data for d...
I want to use my own Model classes in a repository pattern. I don't want to be dependent on the classes that LINQ to SQL generates. Is that viable? How do I handle the Where (and other selections when its a Func<MyModel, bool> but LINQ to SQL wants a Func<LinqToSqlModel, bool>?
I've devised this, but I might be starting to over engineer...
Most of the ASP.NET MVC paging solutions I have found by googling look like they get all rows from a database table in the form of a IEnumerable collection, perform some paging conversion on the IEnumerable collection, and then return the results to the view. I want to be able to page on the DB side but still have some paging class to d...