Linq to sql help

Priyadharshini J.K 1 Reputation point

HI I am currently learning LINQ.
In Visual studio 2022.
Linq to sql classes.
In dbml file , designer.cs, although the codes are autogenerated, I am getting errors. nearly 30 errors.
for example: The type or namespace name 'name' does not exist in the namespace 'namespace' (are you missing an assembly reference?

i just tried to create datagrid view and dragged and dropped a table in form.
and when tried to run the code after creating an instance, couldnot run the code at all due to 30 errors in autogenerated code.
what to be fixed?
why this happens?
kindly help.

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
7,507 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 30,121 Reputation points

    Can you show us your database schema e.g. if using SSMS open the table in design mode and take a screenshot or run the following query

    DECLARE @TableName AS nvarchar(20) = 'Your_TableName'  
    SELECT [Table], [Field],   
    		sysc.colorder [FieldOrder], [DataType],   
    		sysc.[length] [Length],   
    		sysc.prec [Precision],   
    CASE WHEN sysc.scale IS null THEN '-' ELSE sysc.scale END [Scale],   
    CASE WHEN sysc.isnullable = 1 THEN 'True' ELSE 'False' END [AllowNulls],   
    CASE WHEN sysc.[status] = 128 THEN 'True' ELSE 'False' END [Identity],   
    CASE WHEN sysc.colstat = 1 THEN 'True' ELSE 'False' END [PrimaryKey],  
    CASE WHEN fkc.parent_object_id is NULL THEN 'False' ELSE 'True' END [ForeignKey?],   
    CASE WHEN fkc.parent_object_id is null THEN '-' ELSE  END [RelatedTable],  
    CASE WHEN ep.value is NULL THEN '-' ELSE CAST(ep.value as NVARCHAR(500)) END [Description]  
    FROM [sys].[sysobjects] AS syso  
    JOIN [sys].[syscolumns] AS sysc on =  
    LEFT JOIN [sys].[systypes] AS syst ON sysc.xtype = syst.xtype and != 'sysname'  
    LEFT JOIN [sys].[foreign_key_columns] AS fkc on = fkc.parent_object_id and sysc.colid = fkc.parent_column_id      
    LEFT JOIN [sys].[objects] AS obj ON fkc.referenced_object_id = obj.[object_id]  
    LEFT JOIN [sys].[extended_properties] AS ep ON = ep.major_id and sysc.colid = ep.minor_id and = 'MS_Description'  
    WHERE syso.type = 'U' AND != 'sysdiagrams' AND = @TableName  
    ORDER BY [Table], FieldOrder, Field;