Snippets Linq

Get all records (linga.snippet)

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>Get all records</Title>
            <Shortcut>linga</Shortcut>
            <Description>Code snippet for getting all the records in a linq table</Description>
            <Author>Peter De Keyser</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>type</ID>
                    <ToolTip>Data Type</ToolTip>
                    <Default>type</Default>
                </Literal>
            </Declarations>
            <Code Language="csharp">
                <![CDATA[

public static List<$type$> GetAll()
{
  Dataclass dc = new Dataclass();
  IEnumerable<$type$> data = from r in dc.$type$s select r;
  return data.ToList();
}

$end$]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

Get record by id (linid.snippet)

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>Get record by ID</Title>
            <Shortcut>lingid</Shortcut>
            <Description>Code snippet for getting a record by ID in a linq table</Description>
            <Author>Peter De Keyser</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>type</ID>
                    <ToolTip>Data Type</ToolTip>
                    <Default>type</Default>
                </Literal>
            </Declarations>
            <Code Language="csharp">
                <![CDATA[

public static $type$ GetById(long id)
{
  Dataclass dc = new Dataclass();
  $type$ m$type$ = (from r in dc.$type$s where r.$type$ID == id select r).Single();
  return m$type$;
}

$end$]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

Insert record (linins.snippet)

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>Insert record</Title>
            <Shortcut>linins</Shortcut>
            <Description>Code snippet for inserting a record in a linq table</Description>
            <Author>Peter De Keyser</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>type</ID>
                    <ToolTip>Data Type</ToolTip>
                    <Default>type</Default>
                </Literal>
            </Declarations>
            <Code Language="csharp">
                <![CDATA[

public static bool Insert(ref $type$ m$type$)
{
  try
  {
    Dataclass dc = new Dataclass();
    m$type$ = (from l in dc.csTta$type$_I1(m$type$.field1)
               select l).Single() ;
    return true;
  }
  catch (Exception ex)
  {
    //Log.Current.WriteException(ex); // Log exception
    return false;
  }
}

$end$]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

Update record (linupd.snippet)

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>Update record</Title>
            <Shortcut>linupd</Shortcut>
            <Description>Code snippet for updating a record in a linq table</Description>
            <Author>Peter De Keyser</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>type</ID>
                    <ToolTip>Data Type</ToolTip>
                    <Default>type</Default>
                </Literal>
            </Declarations>
            <Code Language="csharp">
                <![CDATA[

public static bool Update(ref $type$ m$type$)
{
  try
  {
    Dataclass dc = new Dataclass();
    m$type$ = (from l in dc.csTta$type$_U1(m$type$.field1)
               select l).Single() ;
    return true;
  }
  catch (Exception ex)
  {
    //Log.Current.WriteException(ex); // Log exception
    return false;
  }
}

$end$]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License