Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace SilverlightTest.Web
{
    public class wcfSpecialLoansImplementation
    {
        SpecialLoansDataContext  db = new SpecialLoansDataContext();
        object specialLoans = from specialLoan in db.SPECIAL_LOAN select specialLoan;
    }
}

this is the code i use to try to use linq to get data from my sqlserver table called SpecialLoans. I have created a linq entity class called SpecialLoans.dbml as seen in an example. the code wont compile cause something seem to be wrong with the section db.SPECIAL_LOAN. it says : A field initializer cannot reference the non-static field, method, or property SilverlightTest.Web.wcfSpecialLoansImplementation.db'
what am i doing wrong?
Posted
Updated 29-Apr-11 3:33am
v2

1 solution

Try putting the initialization of db and specialLoans into the constructor.

C#
public class wcfSpecialLoansImplementation
{
    SpecialLoansDataContext  db;
    object specialLoans;

    public wcfSpecialLoansImplementation
    {
        db = new SpecialLoansDataContext();
        specialLoans = from specialLoan in db.SPECIAL_LOAN select specialLoan;
    }
}
 
Share this answer
 
v2
Comments
alejandronofear 29-Apr-11 10:00am    
worked great mate thanks a lot

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900