Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Linq, DbLinq pitanje

[es] :: .NET :: .NET Desktop razvoj :: Linq, DbLinq pitanje

[ Pregleda: 1836 | Odgovora: 4 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

MarkoBalkan

Član broj: 141124
Poruke: 1624
..128.128-dsl.net.metronet.hr.



+19 Profil

icon Linq, DbLinq pitanje24.02.2010. u 01:12 - pre 172 meseci
našao sam DbLinq koji je proširenje za druge baze, pošto se Linq može koristiti samo sa sql serverom.

http://code.google.com/p/dblinq2007/downloads/list

pošto na temelju baze, generira se se cs file.

međutim ja ne želim koristiti taj generirani file, već svoje query-e.

kako bi se sad to koristilo.

da koristimo taj cs generirani file code bi koristili ovako

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient; //Don't forget to add this line

namespace MySqlLinqTest
{
    class Program
    {
        static void Main(string[] args)
        {
            LinqTest db = new LinqTest(new MySqlConnection("Database=proba;Data Source=localhost;User Id=root;Password=123"));

            var products = from p in db.Products
                           where p.Category == "Sport cars"
                           select p;

            foreach (var product in products)
            {
                Console.WriteLine(product.Name);
            }
        }
    }



ja bi htio koristiti standardni connector + Linq iz ovog dijela.
znači da sam pišem query-e (Linq).

jel može netko malo pomoći?
 
Odgovor na temu

MarkoBalkan

Član broj: 141124
Poruke: 1624
..128.128-dsl.net.metronet.hr.



+19 Profil

icon Re: Linq, DbLinq pitanje24.02.2010. u 01:59 - pre 172 meseci
bez generiranja ništa.

slijedeći problem.

napravio clasu osobe dbml-u.

kako podatke prikazati u datagridu?

Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using DbLinq.MySql;
using DbLinq;
using MySql.Data;

namespace proba
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
          
          Proba1 db = new Proba1(new MySqlConnection("Database=proba;Server=localhost;Uid=root;Pwd=123:Port=3307"));

       
            var query = from p in db.osobes
                           select p;

            foreach (var p in  query)
            {
                      dataGridView1.DataSource =p;
            }
   

           

        }
    }
}



da li je ovo ok?

ne mogu isprobati jer mi javlja neku grešku vezanu uz konekciju.
 
Odgovor na temu

mmix
Miljan Mitrović
Profesorkin muz
Passau, Deutschland

SuperModerator
Član broj: 17944
Poruke: 6042



+4631 Profil

icon Re: Linq, DbLinq pitanje24.02.2010. u 09:04 - pre 172 meseci
Pa ako vezujes na grid trebalo bi da prosto dataGridView1.DataSource = query.ToList() odradi posao.
Sloba je za 12 godina promenio antropološki kod srpskog naroda. On je od jednog naroda koji je bio veseo, pomalo površan, od jednog naroda koji je bio znatiželjan, koji je voleo da vidi, da putuje, da upozna,
od naroda koji je bio kosmopolitski napravio narod koji je namršten, mrzovoljan, sumnjicav, zaplašen, narod koji se stalno nešto žali, kome je stalno neko kriv… - Z.Đinđić
 
Odgovor na temu

MarkoBalkan

Član broj: 141124
Poruke: 1624
..128.128-dsl.net.metronet.hr.



+19 Profil

icon Re: Linq, DbLinq pitanje24.02.2010. u 15:36 - pre 172 meseci
jel mmi može netko pomoći oko generiranja cs file-a za C# za linq.

koristim dblinq
http://code.google.com/p/dblinq2007/downloads/list


a baza je mysql.

za generiranje koristim DbMetal

.bat file

DBMetal.exe -provider=MySql -database:northwind -server:localhost -user:root -password:123 -port=3307 -namespace:WindowsFormsApplication1 -code:nw.cs


nw.dbml file

Code:

<?xml version="1.0" encoding="utf-8"?>
<Database Class="DataClasses1DataContext" xmlns="http://schemas.microsoft.com/linqtosql/dbml/2007">
  <Table Name="" Member="categories">
    <Type Name="categories">
      <Column Name="CategoryID" Type="System.String" CanBeNull="false" />
      <Column Member="Picture" Type="System.String" CanBeNull="false" />
    </Type>
  </Table>
</Database>




nw.cs

Code:

#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.4927
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace WindowsFormsApplication1
{
    using System.Data.Linq;
    using System.Data.Linq.Mapping;
    using System.Data;
    using System.Collections.Generic;
    using System.Reflection;
    using System.Linq;
    using System.Linq.Expressions;
    using System.ComponentModel;
    using System;
    
    
    public partial class DataClasses1DataContext : System.Data.Linq.DataContext
    {
        
        private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
        
    #region Extensibility Method Definitions
    partial void OnCreated();
    #endregion
        
        public DataClasses1DataContext(string connection) : 
                base(connection, mappingSource)
        {
            OnCreated();
        }
        
        public DataClasses1DataContext(System.Data.IDbConnection connection) : 
                base(connection, mappingSource)
        {
            OnCreated();
        }
        
        public DataClasses1DataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) : 
                base(connection, mappingSource)
        {
            OnCreated();
        }
        
        public DataClasses1DataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) : 
                base(connection, mappingSource)
        {
            OnCreated();
        }
        
        public System.Data.Linq.Table<categories> categories
        {
            get
            {
                return this.GetTable<categories>();
            }
        }
    }
    
    [Table(Name="")]
    public partial class categories
    {
        
        private string _CategoryID;
        
        private string _Picture;
        
        public categories()
        {
        }
        
        [Column(Storage="_CategoryID", CanBeNull=false)]
        public string CategoryID
        {
            get
            {
                return this._CategoryID;
            }
            set
            {
                if ((this._CategoryID != value))
                {
                    this._CategoryID = value;
                }
            }
        }
        
        [Column(Storage="_Picture", CanBeNull=false)]
        public string Picture
        {
            get
            {
                return this._Picture;
            }
            set
            {
                if ((this._Picture != value))
                {
                    this._Picture = value;
                }
            }
        }
    }
}
#pragma warning restore 1591





u cmd probam izvršit

C:\DbMetal a.bat

ali dobijem hrpu grešaka.


s time da je dbml file ručno kreiran, schema nije povučena iz baze, a niti se nisam mogao spojiti na bazu tj. s Linq to sql se ne može koristiti sluzbeni konektor za mysql.



Code:


C:\Users\marko\Desktop\DbLinq-0.19\DbLinq-0.19>DbMetal a.bat
DbLinq Database mapping generator 2008 version 0.19
for Microsoft (R) .NET Framework version 3.5
Distributed under the MIT licence (http://linq.to/db/license)

>>> Reading schema from DBML file 'a.bat'
DbMetal failed:System.InvalidOperationException: There is an error in XML docume
nt (3, 1). ---> System.Xml.XmlException: Data at the root level is invalid. Line
 3, position 1.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
   at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XsdValidatingReader.Read()
   at System.Xml.XmlReader.MoveToContent()
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderDataba
se.Read24_Database()
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, St
ring encodingStyle, XmlDeserializationEvents events)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader)
   at DbLinq.Schema.Dbml.DbmlSerializer.Read(Stream xmlStream, IList`1 validatio
nErrors) in Z:\Development\DbLinq-0.19\src\DbLinq\Schema\Dbml\DbmlSerializer.cs:
line 102
   at DbLinq.Schema.Dbml.DbmlSerializer.Read(Stream xmlStream) in Z:\Development
\DbLinq-0.19\src\DbLinq\Schema\Dbml\DbmlSerializer.cs:line 116
   at DbMetal.Generator.Implementation.Processor.ReadSchema(Parameters parameter
s, String filename) in Z:\Development\DbLinq-0.19\src\DbMetal\Generator\Implemen
tation\Processor.cs:line 247
   at DbMetal.Generator.Implementation.Processor.ReadSchema(Parameters parameter
s, ISchemaLoader& schemaLoader) in Z:\Development\DbLinq-0.19\src\DbMetal\Genera
tor\Implementation\Processor.cs:line 216
   at DbMetal.Generator.Implementation.Processor.ProcessSchema(Parameters parame
ters) in Z:\Development\DbLinq-0.19\src\DbMetal\Generator\Implementation\Process
or.cs:line 116

C:\Users\marko\Desktop\DbLinq-0.19\DbLinq-0.19>




javlja mi grešku za xml, a dbml generiran iz visual studija.

visual studio je 2008 sp1

 
Odgovor na temu

MarkoBalkan

Član broj: 141124
Poruke: 1624
..128.128-dsl.net.metronet.hr.



+19 Profil

icon Re: Linq, DbLinq pitanje24.02.2010. u 17:03 - pre 172 meseci
uspio sam generirat file.

select radi ok, ali ne radi mi insert.

Code:

 nw.ProBa db = new nw.ProBa(new MySqlConnection("Database=proba;Data Source=localhost;Uid=root;Pwd=123"));

            db.OSobE.InsertOnSubmit(new nw.OSobE {ID=2,IMe="ivo" });
           
            db.SubmitChanges();


greška: "Value cannot be null.\r\nParameter name: key"}

miješana slova, velika i mala, tako mi je generirao DbMetal.
 
Odgovor na temu

[es] :: .NET :: .NET Desktop razvoj :: Linq, DbLinq pitanje

[ Pregleda: 1836 | Odgovora: 4 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.