I'm trying to use dblinq in my IronPython application but am having some problems getting started. When trying to import dblinq classes,using clr.AddReference() it does not seem to see dblinq.

I can build but not access the library

import clr
clr.AddReference("DbLinq")
clr.AddReference("System.Data.Linq")
from System.Data.Linq import DataContext

exit = raw_input("press any key to quit")

1: My dblinq source is in a subfolder called Resources

clr.AddReferenceToFileAndPath("Resources/DbLinq.dll") => file not found

clr.AddReference("DbLinq") => could not add reference to dblinq

clr.AddReferenceToFileAndPath("C:/Development/DBLinq2/Dblinq.dll" => success

but still cannot use the classes using from DbLinq import ...

Solution

    import clr

   clr.AddReferenceToFileAndPath("%s\Resources\DbLinq.dll" %os.getcwd())
    clr.AddReference("DbLinq")
    from Npgsql import *
    from DbLinq import Data
有帮助吗?

解决方案

For libraries like DbLinq that come with dependencies or are split into several DLLs/modules you can programmatically add their location to allow the runtime to find all required files.

import sys
sys.path.append(r"C:\Temp\DbLinq-0.20.1")

You can then reference all required assemblies as usual:

clr.AddReference("DbLinq")

If there is one primary assembly you can also use clr.AddReferenceToFileAndPath (with an absolute path) which will implicitly add the referenced assemblies location to the path.

clr.AddReference(r"C:\Temp\DbLinq-0.20.1\DbLinq.dll")
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top