Linq to sql help

Priyadharshini J.K 1 Reputation point
2022-08-15T15:11:57.037+00:00

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.

C#
C#
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.
10,288 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 35,116 Reputation points
    2022-08-15T20:01:44.58+00:00

    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	syso.name [Table],  
    		sysc.name [Field],   
    		sysc.colorder [FieldOrder],   
    		syst.name [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 obj.name  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 syso.id = sysc.id  
    LEFT JOIN [sys].[systypes] AS syst ON sysc.xtype = syst.xtype and syst.name != 'sysname'  
    LEFT JOIN [sys].[foreign_key_columns] AS fkc on syso.id = 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 syso.id = ep.major_id and sysc.colid = ep.minor_id and ep.name = 'MS_Description'  
    WHERE syso.type = 'U' AND  syso.name != 'sysdiagrams' AND syso.name = @TableName  
    ORDER BY [Table], FieldOrder, Field;  
    
    0 comments No comments