WCF/WF - Return properties ?

Asked By miho stumi
28-Oct-11 03:00 AM
Hi i've got a class with 3 properties: Tytul,kod,skrot and now i want return something like this:

public List <WynikZnajdzDokument> ZnajdzDokument(string tytul, string kod, string skrot)
        {
            using (ArchiwumDataContext Db = new ArchiwumDataContextFabryka().ArchiwumDataContext())
            {
                var tytuly = Db.Tytuls.Select(t => t);
                if (!string.IsNullOrEmpty(tytul))
                    tytuly = tytuly.Where(t => t.TytulPublikatora == tytul);
                if (!string.IsNullOrEmpty(kod))
                    tytuly = tytuly.Where(k => k.Kod == kod);
                if (!string.IsNullOrEmpty(skrot))
                    tytuly = tytuly.Where(s => s.Skrot == skrot);
                return new WynikZnajdzDokument { Tytul = tytuly.tytul, Kod = tytuly.kod, Skrot = tytuly.skrot };                
            }
        }

to use that properties Tytul,kod and skrot in my application,but i got an error 
"'System.Linq.IQueryable<Tytul>' does not contain a definition for 'tytul' and no extension method 'tytul' accepting a first argument of type 'System.Linq.IQueryable<Tytul>' could be found (are you missing a using directive or an assembly reference?)

"
  Vickey F replied to miho stumi
28-Oct-11 03:06 AM
change this line-


return new WynikZnajdzDokument { Tytul = tytuly.select(s => s.tytul), Kod = tytuly.select(s => s.kod), Skrot = tytuly.select(s => s.skrot )};


Try this and let me know.






  miho stumi replied to Vickey F
28-Oct-11 03:11 AM
It doesn't work i got "Error 3 Cannot implicitly convert type 'System.Linq.IQueryable<string>' to 'string"
  miho stumi replied to Vickey F
28-Oct-11 03:38 AM
OK i change in properties from string to IQuerable<string> but i got Error 3 Cannot implicitly convert type WynikZnajdzDokument' WynikZnajdzDokument[]' but it have to a table because i want return many objects with this 3 properties.
I tried like this:

var q = from d in Db.Tytuls
                        where d.TytulPublikatora == tytul || d.Kod == kod || d.Skrot == skrot
                        select new WynikZnajdzDokument { Tytul = d.TytulPublikatora, Kod = d.Kod, Skrot = d.Skrot };
                return q;
but i got the same problem,any ideas ?

  Vickey F replied to miho stumi
28-Oct-11 04:35 AM
Ok then change your code like this-

public List <WynikZnajdzDokument> ZnajdzDokument(string tytul, string kod, string skrot)
        {
            using (ArchiwumDataContext Db = new ArchiwumDataContextFabryka().ArchiwumDataContext())
            {
                var tytuly = Db.Tytuls.Select(t => t);
                if (!string.IsNullOrEmpty(tytul))
                    tytuly = tytuly.Where(t => t.TytulPublikatora == tytul);
                if (!string.IsNullOrEmpty(kod))
                    tytuly = tytuly.Where(k => k.Kod == kod);
                if (!string.IsNullOrEmpty(skrot))
                    tytuly = tytuly.Where(s => s.Skrot == skrot);

        WynikZnajdzDokument  obj= null;
        foreach(var item in tytuly )
          {
          WynikZnajdzDokument  obj= new WynikZnajdzDokument ();
          obj.Tytul = item.tytul;
          obj.Kod = item.kod;
          obj.Skrot = item.skrot;
          }


                return obj;            
            }

Try this code and let me know.
        }
  Vickey F replied to miho stumi
28-Oct-11 04:37 AM
Ok then change your code like this-

public List <WynikZnajdzDokument> ZnajdzDokument(string tytul, string kod, string skrot)
        {
            using (ArchiwumDataContext Db = new ArchiwumDataContextFabryka().ArchiwumDataContext())
            {
                var tytuly = Db.Tytuls.Select(t => t);
                if (!string.IsNullOrEmpty(tytul))
                    tytuly = tytuly.Where(t => t.TytulPublikatora == tytul);
                if (!string.IsNullOrEmpty(kod))
                    tytuly = tytuly.Where(k => k.Kod == kod);
                if (!string.IsNullOrEmpty(skrot))
                    tytuly = tytuly.Where(s => s.Skrot == skrot);

      WynikZnajdzDokument  obj= null;
      foreach(var item in tytuly )
      {
      WynikZnajdzDokument  obj= new WynikZnajdzDokument ();
      obj.Tytul = item.tytul;
      obj.Kod = item.kod;
      obj.Skrot = item.skrot;
      }


                return obj;            
            }
        }

Let me know.
  miho stumi replied to Vickey F
28-Oct-11 04:57 AM
the same error can not WynikZnajdzDokument to List<WynikZnajdzDokument>
  Vickey F replied to miho stumi
28-Oct-11 05:42 AM
oh , actually your return type is list type.

Use this code-


public List <WynikZnajdzDokument> ZnajdzDokument(string tytul, string kod, string skrot)
        {
            using (ArchiwumDataContext Db = new ArchiwumDataContextFabryka().ArchiwumDataContext())
            {
                var tytuly = Db.Tytuls.Select(t => t);
                if (!string.IsNullOrEmpty(tytul))
                    tytuly = tytuly.Where(t => t.TytulPublikatora == tytul);
                if (!string.IsNullOrEmpty(kod))
                    tytuly = tytuly.Where(k => k.Kod == kod);
                if (!string.IsNullOrEmpty(skrot))
                    tytuly = tytuly.Where(s => s.Skrot == skrot);

   List<WynikZnajdzDokument>  lstObj=new List<WynikZnajdzDokument>();

    foreach(var item in tytuly )
    {
    WynikZnajdzDokument  obj= new WynikZnajdzDokument ();
    obj.Tytul = item.tytul;
    obj.Kod = item.kod;
    obj.Skrot = item.skrot;
     lstObj.Add(obj);
    }


                return lstObj;            
            }
        }

Let me know.
  miho stumi replied to Vickey F
02-Nov-11 06:29 AM
Ok that's work,thanks.
  Vickey F replied to miho stumi
02-Nov-11 06:51 AM
you always welcome.
Create New Account
help
summary> / / / Implements the chat service interface. / / / < / summary> [ ServiceBehavior (InstanceContextMode = InstanceContextMode .Single, ConcurrencyMode = ConcurrencyMode .Multiple)] public class ChatService : IChatService { private readonly Dictionary < Guid , IChatServiceCallback > clients = new Dictionary < Guid , IChatServiceCallback > (); #region IChatService Guid the server / / can't connect to the client. It might be because of a network / / error, or the client was closed prematurely due to an exception or / / and was unable to disconnectedClientGuids.Add(client.Key); } } foreach ( Guid clientGuid in disconnectedClientGuids) { clients.Remove(clientGuid); } } } ); } } Notice that the class is adorned with the following attribute. [ ServiceBehavior (InstanceContextMode = InstanceContextMode .Single, ConcurrencyMode = ConcurrencyMode .Multiple)] There are The following code listing shows the implementation. / / / <summary> / / / Implementation of the callback contract. / / / < / summary> public class ChatServiceCallback : IChatServiceCallback { public event ClientNotifiedEventHandler ClientNotified; / / / <summary> / / / Notifies the client of the message by raising message)); } } } public delegate void ClientNotifiedEventHandler ( object sender, ClientNotifiedEventArgs e); / / / <summary> / / / Custom event arguments. / / / < / summary> public class ClientNotifiedEventArgs : EventArgs { private readonly string message; / / / <summary> / / / Constructor. / / / < / summary> / / / <param name = "message"> Message from server The following shows the MainWindow code. / / / <summary> / / / Interaction logic for MainWindow.xaml / / / < / summary> public partial class MainWindow : Window { private Guid clientId; private ChatServiceClient chatServiceClient; private InstanceContext instanceContext; / / / <summary> / / / Constructor. / / / < / summary> public Ignored. < / param> private void Btn_Click( object sender, RoutedEventArgs e) { string message = messageTbx.Text; if (! string .IsNullOrEmpty(message)) { try { if (chatServiceClient.State = = CommunicationState .Faulted) { chatServiceClient.Abort(); chatServiceClient = new ChatServiceClient (instanceContext); } chatServiceClient.SendMessage the message from the server. < / param> private void ChatServiceCallback_ClientNotified( object sender, ClientNotifiedEventArgs e) { if (! string .IsNullOrEmpty(conferenceTbx.Text)) { conferenceTbx.Text + = " \ n" ; } conferenceTbx.Text + = e.Message; } } When the window is loaded, the
Null Object Error. Driving me crazy. Please, help me out . . . .NET Framework Hello, I am having a problem with a C# class for hours and I cannot find the problem. Basically a Web Application works fine but when Google Verify, Spider, W3C validation try to access the page a 500 error is generated. I was able to identify where the error is and created a simple web application: http: / / www.flyondreams.net / Note: If you access directly everything works fine. I then used Rex Swain's HTTP Viewer which shows what error occurs when the page is accessed: http: / / www.rexswain.com / cgi-bin / httpview.cgi And displays the stack . . . Just submit with http: / / www.flyondreams.net / . I get the error: Object = B7reference = B7not = B7set = B7to = B7an = B7instance = B7of = B7an = B7object. I am having problems in Generic; using System.Globalization; using System.Web; using System.Web.Mvc; namespace MvcApplication1.ActionFilter { public class SetCultureAttribute : FilterAttribute, IActionFilter { public void OnActionExecuting(ActionExecutingContext filterContext) { string cultureCode = 3D SetCurrentLanguage(filterContext); if (string.IsNullOrEmpty(cultureCode)) return; HttpContext.Current.Response.Cookies.Add( new HttpCookie("Culture", cultureCode) { HttpOnly = 3D true, Expires
calling class file gives error i have a class file in app_code when i use it in .cs page i get error Hello h = new Hello(); What error you are getting? Make sure you have a default constructor in your class file: public Hello() { } What error you are getting? using http: / / stackoverflow.com / questions / 202011 / encrypt-decrypt-string-in-net the code frm here in a class file error nr byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(ToEncrypt); CS0103: The name 'UTF8Encoding' does not
Mapping .NET Framework Hello, I am mapping a class Error to another class YError: YError ToY(Error error) { return new YError { Id = error.ErrorId, CreatedAt = error.CreatedAt, Description = error.Description, HttpCode = error.HttpCode, }; } / / ToY Now I am trying a new version that does the
new in asp.net i have this error message: Server Error in ' / electronix' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0131: The left-hand side of an assignment must be a variable, property or indexer Source Error: Line 9: string a; Line 10: a = Session["login"].ToString(); Line 11: if (a.ToString 2001-2005. All rights reserved. c: \ Users \ m7md \ Desktop \ electronix \ electronix \ MasterPage.master(11, 13): error CS0131: The left-hand side of an assignment must be a variable, property or indexer